Explicitly cast fuchsia.io constants to uint32_t (flutter/engine#32250)

This commit is contained in:
Tamir Duberstein 2022-03-24 18:35:03 -04:00 committed by GitHub
parent c68cde8a7b
commit ec3cbc1635
3 changed files with 26 additions and 28 deletions

View File

@ -4,6 +4,7 @@
#include "file_in_namespace_buffer.h"
#include <fuchsia/io/cpp/fidl.h>
#include <lib/fdio/directory.h>
#include <zircon/status.h>
@ -16,17 +17,6 @@
namespace flutter_runner {
namespace {
// TODO(kaushikiska): Use these constants from ::llcpp::fuchsia::io
// Can read from target object.
constexpr uint32_t OPEN_RIGHT_READABLE = 1u;
// Connection can map target object executable.
constexpr uint32_t OPEN_RIGHT_EXECUTABLE = 8u;
} // namespace
FileInNamespaceBuffer::FileInNamespaceBuffer(int namespace_fd,
const char* path,
bool executable)
@ -84,15 +74,16 @@ std::unique_ptr<fml::Mapping> LoadFile(int namespace_fd,
std::unique_ptr<fml::FileMapping> MakeFileMapping(const char* path,
bool executable) {
uint32_t flags = OPEN_RIGHT_READABLE;
auto flags = fuchsia::io::OPEN_RIGHT_READABLE;
if (executable) {
flags |= OPEN_RIGHT_EXECUTABLE;
flags |= fuchsia::io::OPEN_RIGHT_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, flags, &fd);
const zx_status_t status =
fdio_open_fd(path, static_cast<uint32_t>(flags), &fd);
if (status != ZX_OK) {
return nullptr;
}

View File

@ -109,15 +109,17 @@ static int OpenFdExec(const std::string& path, int dirfd) {
// fdio_open_fd_at does not support AT_FDCWD, by design. Use fdio_open_fd
// and expect an absolute path for that usage pattern.
dart_utils::Check(path[0] == '/', LOG_TAG);
result = fdio_open_fd(
path.c_str(),
fuchsia::io::OPEN_RIGHT_READABLE | fuchsia::io::OPEN_RIGHT_EXECUTABLE,
&fd);
result =
fdio_open_fd(path.c_str(),
static_cast<uint32_t>(fuchsia::io::OPEN_RIGHT_READABLE |
fuchsia::io::OPEN_RIGHT_EXECUTABLE),
&fd);
} else {
dart_utils::Check(path[0] != '/', LOG_TAG);
result = fdio_open_fd_at(
dirfd, path.c_str(),
fuchsia::io::OPEN_RIGHT_READABLE | fuchsia::io::OPEN_RIGHT_EXECUTABLE,
static_cast<uint32_t>(fuchsia::io::OPEN_RIGHT_READABLE |
fuchsia::io::OPEN_RIGHT_EXECUTABLE),
&fd);
}
if (result != ZX_OK) {

View File

@ -59,12 +59,14 @@ bool VmoFromFilename(const std::string& filename,
// 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.
uint32_t flags = fuchsia::io::OPEN_RIGHT_READABLE |
(executable ? fuchsia::io::OPEN_RIGHT_EXECUTABLE : 0);
zx_status_t status;
int fd;
auto flags = fuchsia::io::OPEN_RIGHT_READABLE;
if (executable) {
flags |= fuchsia::io::OPEN_RIGHT_EXECUTABLE;
}
status = fdio_open_fd(filename.c_str(), flags, &fd);
int fd;
const zx_status_t status =
fdio_open_fd(filename.c_str(), static_cast<uint32_t>(flags), &fd);
if (status != ZX_OK) {
FX_LOGF(ERROR, LOG_TAG, "fdio_open_fd(\"%s\", %08x) failed: %s",
filename.c_str(), flags, zx_status_get_string(status));
@ -79,11 +81,14 @@ bool VmoFromFilenameAt(int dirfd,
const std::string& filename,
bool executable,
fuchsia::mem::Buffer* buffer) {
uint32_t flags = fuchsia::io::OPEN_RIGHT_READABLE |
(executable ? fuchsia::io::OPEN_RIGHT_EXECUTABLE : 0);
zx_status_t status;
auto flags = fuchsia::io::OPEN_RIGHT_READABLE;
if (executable) {
flags |= fuchsia::io::OPEN_RIGHT_EXECUTABLE;
}
int fd;
status = fdio_open_fd_at(dirfd, filename.c_str(), flags, &fd);
const zx_status_t status = fdio_open_fd_at(dirfd, filename.c_str(),
static_cast<uint32_t>(flags), &fd);
if (status != ZX_OK) {
FX_LOGF(ERROR, LOG_TAG, "fdio_open_fd_at(%d, \"%s\", %08x) failed: %s",
dirfd, filename.c_str(), flags, zx_status_get_string(status));