6#if defined(DART_HOST_OS_FUCHSIA)
12#include <lib/fdio/fdio.h>
13#include <lib/fdio/namespace.h>
35 int fd()
const {
return fd_; }
36 void set_fd(
int fd) {
fd_ =
fd; }
45 if (!
IsClosed() && (handle_->
fd() != STDOUT_FILENO) &&
46 (handle_->
fd() != STDERR_FILENO)) {
54 if (handle_->
fd() == STDOUT_FILENO) {
56 auto* null_fdio = fdio_null_create();
57 ASSERT(null_fdio !=
nullptr);
70 handle_->set_fd(kClosedFd);
78 return handle_->
fd() == kClosedFd;
89 int flags = MAP_PRIVATE;
97 prot = PROT_READ | PROT_EXEC;
100 prot = PROT_READ | PROT_WRITE;
103 if (start !=
nullptr) {
108 if (
addr == MAP_FAILED) {
111 return new MappedMemory(
addr,
length, start ==
nullptr);
114void MappedMemory::Unmap() {
115 int result = munmap(address_, size_);
133 va_list measure_args;
134 va_copy(measure_args,
args);
142 va_copy(print_args,
args);
173 ASSERT((end == -1) || (end > start));
190 fl.l_whence = SEEK_SET;
210File* File::FileOpenW(
const wchar_t* system_name, FileOpenMode
mode) {
216 return new File(
new FileHandle(fd));
220 NamespaceScope ns(namespc,
name);
224 if (S_ISDIR(st.st_mode)) {
229 int flags = O_RDONLY;
232 flags = (O_RDWR | O_CREAT);
236 flags = (O_WRONLY | O_CREAT);
248 int64_t position = lseek(fd, 0, SEEK_END);
258 (strlen(uri) >= 8 && strncmp(uri,
"file:///", 8) == 0) ? uri + 7 : uri;
259 UriDecoder uri_decoder(
path);
260 if (uri_decoder.decoded() ==
nullptr) {
269 if (
path ==
nullptr) {
276 return new File(
new FileHandle(fd));
280 NamespaceScope ns(namespc,
name);
284 return !S_ISDIR(st.st_mode) && !S_ISLNK(st.st_mode);
291 if (
path ==
nullptr) {
298 NamespaceScope ns(namespc,
name);
299 int flags = O_RDONLY | O_CREAT | O_CLOEXEC;
306 ns.path(), strerror(errno));
312 bool is_file =
false;
316 if (S_ISDIR(st.st_mode)) {
319 }
else if (S_ISLNK(st.st_mode)) {
331 NamespaceScope ns(namespc,
name);
335bool File::CreatePipe(Namespace* namespc, File** readPipe, File** writePipe) {
341 *readPipe =
OpenFD(pipe_fds[0]);
342 *writePipe =
OpenFD(pipe_fds[1]);
349 NamespaceScope ns(namespc,
name);
350 struct stat entry_info;
357 fstatat(ns.fd(), ns.path(), &entry_info, AT_SYMLINK_NOFOLLOW));
359 if (stat_success == -1) {
362 if (S_ISDIR(entry_info.st_mode)) {
365 if (S_ISREG(entry_info.st_mode)) {
368 if (S_ISLNK(entry_info.st_mode)) {
371 if (S_ISSOCK(entry_info.st_mode)) {
374 if (S_ISFIFO(entry_info.st_mode)) {
394static bool CheckTypeAndSetErrno(Namespace* namespc,
399 if (actual == expected) {
409 NamespaceScope ns(namespc,
name);
417 NamespaceScope ns(namespc,
name);
418 return CheckTypeAndSetErrno(namespc,
name,
kIsLink,
false) &&
423 const char* old_path,
424 const char* new_path) {
427 NamespaceScope oldns(namespc, old_path);
428 NamespaceScope newns(namespc, new_path);
430 newns.path())) == 0);
437 const char* old_path,
438 const char* new_path) {
439 NamespaceScope oldns(namespc, old_path);
440 NamespaceScope newns(namespc, new_path);
441 return CheckTypeAndSetErrno(namespc, old_path,
kIsLink,
false) &&
443 newns.path())) == 0);
447 const char* old_path,
448 const char* new_path) {
454 NamespaceScope oldns(namespc, old_path);
464 NamespaceScope newns(namespc, new_path);
466 openat(newns.fd(), newns.path(), O_WRONLY | O_TRUNC | O_CREAT | O_CLOEXEC,
495static bool StatHelper(Namespace* namespc,
const char*
name,
struct stat* st) {
496 NamespaceScope ns(namespc,
name);
501 if (S_ISDIR(st->st_mode)) {
511 if (!StatHelper(namespc,
name, &st)) {
517static int64_t TimespecToMilliseconds(
const struct timespec& t) {
518 return static_cast<int64_t
>(t.tv_sec) * 1000L +
519 static_cast<int64_t
>(t.tv_nsec) / 1000000L;
522static void MillisecondsToTimespec(int64_t millis,
struct timespec* t) {
529 NamespaceScope ns(namespc,
name);
532 if (S_ISREG(st.st_mode)) {
534 }
else if (S_ISDIR(st.st_mode)) {
536 }
else if (S_ISLNK(st.st_mode)) {
538 }
else if (S_ISSOCK(st.st_mode)) {
540 }
else if (S_ISFIFO(st.st_mode)) {
557 if (!StatHelper(namespc,
name, &st)) {
565 if (!StatHelper(namespc,
name, &st)) {
576 if (!StatHelper(namespc,
name, &st)) {
581 NamespaceScope ns(namespc,
name);
582 struct timespec
times[2];
583 MillisecondsToTimespec(millis, &
times[0]);
584 times[1] = st.st_mtim;
585 return utimensat(ns.fd(), ns.path(),
times, 0) == 0;
593 if (!StatHelper(namespc,
name, &st)) {
598 NamespaceScope ns(namespc,
name);
599 struct timespec
times[2];
600 times[0] = st.st_atim;
601 MillisecondsToTimespec(millis, &
times[1]);
602 return utimensat(ns.fd(), ns.path(),
times, 0) == 0;
609 NamespaceScope ns(namespc,
name);
610 struct stat link_stats;
612 fstatat(ns.fd(), ns.path(), &link_stats, AT_SYMLINK_NOFOLLOW));
616 if (!S_ISLNK(link_stats.st_mode)) {
625 const int target_size =
627 if (target_size <= 0) {
630 if (
dest ==
nullptr) {
634 if (dest_size <= target_size) {
639 dest[target_size] =
'\0';
644 return ((pathname !=
nullptr) && (pathname[0] ==
'/'));
651 if (
name ==
nullptr) {
661 if (
dest ==
nullptr) {
669 }
while ((abs_path ==
nullptr) && (errno == EINTR));
671 ASSERT(abs_path ==
nullptr || (abs_path ==
dest));
683static int fd_is_valid(
int fd) {
696 if (S_ISCHR(buf.st_mode)) {
699 if (S_ISFIFO(buf.st_mode)) {
702 if (S_ISSOCK(buf.st_mode)) {
705 if (S_ISREG(buf.st_mode)) {
713 Namespace* namespc_2,
714 const char* file_2) {
715 struct stat file_1_info;
716 struct stat file_2_info;
719 NamespaceScope ns1(namespc_1, file_1);
721 fstatat(ns1.fd(), ns1.path(), &file_1_info, AT_SYMLINK_NOFOLLOW));
727 NamespaceScope ns2(namespc_2, file_2);
729 fstatat(ns2.fd(), ns2.path(), &file_2_info, AT_SYMLINK_NOFOLLOW));
734 return ((file_1_info.st_ino == file_2_info.st_ino) &&
735 (file_1_info.st_dev == file_2_info.st_dev))
static SkISize times(const SkISize &size, float factor)
static bool read(SkStream *stream, void *buffer, size_t amount)
static const size_t kBufferSize
static void PrintErr(const char *format,...) PRINTF_ATTRIBUTE(1
static int static int VSNPrint(char *str, size_t size, const char *format, va_list args)
static char * StrError(int err, char *buffer, size_t bufsize)
static char * ScopedCString(intptr_t length)
static void SaveErrorAndClose(intptr_t fd)
FileHandle(HANDLE handle)
static bool CreatePipe(Namespace *namespc, File **readPipe, File **writePipe)
static bool DeleteLink(Namespace *namespc, const char *path)
static bool IsAbsolutePath(const char *path)
MappedMemory * Map(MapType type, int64_t position, int64_t length, void *start=nullptr)
static const char * GetCanonicalPath(Namespace *namespc, const char *path, char *dest=nullptr, int dest_size=0)
static CStringUniquePtr UriToPath(const char *uri)
int64_t Read(void *buffer, int64_t num_bytes)
static bool SetLastAccessed(Namespace *namespc, const char *path, int64_t millis)
static File * OpenUri(Namespace *namespc, const char *uri, FileOpenMode mode)
static bool SetLastModified(Namespace *namespc, const char *path, int64_t millis)
static time_t LastModified(Namespace *namespc, const char *path)
static void Stat(Namespace *namespc, const char *path, int64_t *data)
static const char * PathSeparator()
static bool Create(Namespace *namespc, const char *path, bool exclusive)
bool VPrint(const char *format, va_list args)
static bool Rename(Namespace *namespc, const char *old_path, const char *new_path)
static bool Delete(Namespace *namespc, const char *path)
static const char * StringEscapedPathSeparator()
bool WriteFully(const void *buffer, int64_t num_bytes)
static int64_t LengthFromPath(Namespace *namespc, const char *path)
static bool Copy(Namespace *namespc, const char *old_path, const char *new_path)
static time_t LastAccessed(Namespace *namespc, const char *path)
int64_t Write(const void *buffer, int64_t num_bytes)
static bool Exists(Namespace *namespc, const char *path)
static File * Open(Namespace *namespc, const char *path, FileOpenMode mode)
bool Lock(LockType lock, int64_t start, int64_t end)
bool SetPosition(int64_t position)
static Identical AreIdentical(Namespace *namespc_1, const char *file_1, Namespace *namespc_2, const char *file_2)
static File * OpenFD(int fd)
static const char * LinkTarget(Namespace *namespc, const char *pathname, char *dest=nullptr, int dest_size=0)
static bool CreateLink(Namespace *namespc, const char *path, const char *target)
static bool ExistsUri(Namespace *namespc, const char *uri)
static File * OpenStdio(int fd)
static StdioHandleType GetStdioHandleType(int fd)
static Type GetType(Namespace *namespc, const char *path, bool follow_links)
bool Truncate(int64_t length)
static bool RenameLink(Namespace *namespc, const char *old_path, const char *new_path)
static bool IsDefault(Namespace *namespc)
FlutterSemanticsFlag flags
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
uint32_t uint32_t * format
CAllocUniquePtr< char > CStringUniquePtr
void * malloc(size_t size)
DART_EXPORT char * Dart_Initialize(Dart_InitializeParams *params)
constexpr intptr_t kMillisecondsPerSecond
static int8_t data[kExtLength]
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
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 vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive mode
char * strdup(const char *str1)
#define NO_RETRY_EXPECTED(expression)
#define VOID_NO_RETRY_EXPECTED(expression)
#define TEMP_FAILURE_RETRY(expression)
void write(SkWStream *wStream, const T &text)