2013-09-03 12:43:08 +00:00
|
|
|
// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
|
|
|
|
// for details. All rights reserved. Use of this source code is governed by a
|
|
|
|
// BSD-style license that can be found in the LICENSE file.
|
|
|
|
|
|
|
|
#include "platform/globals.h"
|
2021-07-02 19:06:45 +00:00
|
|
|
#if defined(DART_HOST_OS_WINDOWS)
|
2013-09-03 12:43:08 +00:00
|
|
|
|
|
|
|
#include "bin/file_system_watcher.h"
|
|
|
|
|
[vm] Fix some cross compilation issues from Linux to Windows
Upstreamed changes from cl/579854752.
The cross-compiler checks some things that are check on Windows.
* Correct capitalization of filenames in includes.
* Field initialization order in constructors.
In the cross compilation process, some binaries are run on the host.
This unveiled missing `UnwindingRecords::GenerateRecordsInto`.
Finally, when emitting blob data with a symbol in assembly, the
`.type` directive is not supported but the format should still be
unix style assemble. So this CL introduces "win_gnu". This tool is
directly invoked from the build-rules in cl/579854752, and will not be
used until we address https://github.com/dart-lang/sdk/issues/28617.
TEST=windows bots
Change-Id: I94256589e8c231b45b8e14a63727c782416c2e98
Cq-Include-Trybots: luci.dart.try:vm-aot-win-debug-arm64-try,vm-aot-win-debug-x64c-try,pkg-win-release-try,pkg-win-release-arm64-try,vm-win-debug-arm64-try,vm-win-debug-x64c-try,vm-win-debug-x64-try,vm-msvc-windows-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/335520
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
2023-11-13 14:25:28 +00:00
|
|
|
#include <winioctl.h> // NOLINT
|
2013-09-03 12:43:08 +00:00
|
|
|
|
|
|
|
#include "bin/builtin.h"
|
2016-03-16 17:01:00 +00:00
|
|
|
#include "bin/eventhandler.h"
|
2013-09-03 12:43:08 +00:00
|
|
|
#include "bin/utils.h"
|
2015-06-24 08:36:05 +00:00
|
|
|
#include "bin/utils_win.h"
|
2019-04-22 20:15:43 +00:00
|
|
|
#include "platform/syslog.h"
|
2013-09-03 12:43:08 +00:00
|
|
|
|
|
|
|
namespace dart {
|
|
|
|
namespace bin {
|
|
|
|
|
2013-09-03 15:42:02 +00:00
|
|
|
bool FileSystemWatcher::IsSupported() {
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-12-04 10:35:00 +00:00
|
|
|
intptr_t FileSystemWatcher::Init() {
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void FileSystemWatcher::Close(intptr_t id) {
|
|
|
|
USE(id);
|
|
|
|
}
|
|
|
|
|
|
|
|
intptr_t FileSystemWatcher::WatchPath(intptr_t id,
|
2017-08-30 16:34:34 +00:00
|
|
|
Namespace* namespc,
|
2013-12-04 10:35:00 +00:00
|
|
|
const char* path,
|
2013-09-03 12:43:08 +00:00
|
|
|
int events,
|
|
|
|
bool recursive) {
|
2013-12-04 10:35:00 +00:00
|
|
|
USE(id);
|
2016-10-21 21:55:37 +00:00
|
|
|
Utf8ToWideScope name(path);
|
2023-04-12 01:11:05 +00:00
|
|
|
HANDLE dir =
|
|
|
|
CreateFileW(name.wide(), FILE_LIST_DIRECTORY,
|
|
|
|
FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
|
|
|
|
nullptr, OPEN_EXISTING,
|
|
|
|
FILE_FLAG_BACKUP_SEMANTICS | FILE_FLAG_OVERLAPPED, nullptr);
|
2013-09-03 12:43:08 +00:00
|
|
|
|
|
|
|
if (dir == INVALID_HANDLE_VALUE) {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int list_events = 0;
|
2016-03-16 17:01:00 +00:00
|
|
|
if ((events & (kCreate | kMove | kDelete)) != 0) {
|
2016-11-04 19:30:56 +00:00
|
|
|
list_events |= FILE_NOTIFY_CHANGE_FILE_NAME | FILE_NOTIFY_CHANGE_DIR_NAME;
|
2013-09-03 12:43:08 +00:00
|
|
|
}
|
2016-03-16 17:01:00 +00:00
|
|
|
if ((events & kModifyContent) != 0) {
|
|
|
|
list_events |= FILE_NOTIFY_CHANGE_LAST_WRITE;
|
|
|
|
}
|
2013-09-03 12:43:08 +00:00
|
|
|
|
2013-10-02 11:10:13 +00:00
|
|
|
DirectoryWatchHandle* handle =
|
|
|
|
new DirectoryWatchHandle(dir, list_events, recursive);
|
2019-09-09 23:16:52 +00:00
|
|
|
// Issue a read directly, to be sure events are tracked from now on. This is
|
2023-01-06 07:48:22 +00:00
|
|
|
// okay, since in Dart, we create the socket and start reading immediately.
|
2019-09-09 23:16:52 +00:00
|
|
|
handle->EnsureInitialized(EventHandler::delegate());
|
|
|
|
handle->IssueRead();
|
2013-10-02 11:10:13 +00:00
|
|
|
return reinterpret_cast<intptr_t>(handle);
|
2013-09-03 12:43:08 +00:00
|
|
|
}
|
|
|
|
|
2013-12-04 10:35:00 +00:00
|
|
|
void FileSystemWatcher::UnwatchPath(intptr_t id, intptr_t path_id) {
|
|
|
|
USE(id);
|
2014-06-04 10:23:32 +00:00
|
|
|
DirectoryWatchHandle* handle =
|
|
|
|
reinterpret_cast<DirectoryWatchHandle*>(path_id);
|
|
|
|
handle->Stop();
|
2013-09-03 12:43:08 +00:00
|
|
|
}
|
|
|
|
|
2013-12-04 10:35:00 +00:00
|
|
|
intptr_t FileSystemWatcher::GetSocketId(intptr_t id, intptr_t path_id) {
|
|
|
|
USE(id);
|
|
|
|
return path_id;
|
2013-09-03 12:43:08 +00:00
|
|
|
}
|
|
|
|
|
2013-12-04 10:35:00 +00:00
|
|
|
Dart_Handle FileSystemWatcher::ReadEvents(intptr_t id, intptr_t path_id) {
|
|
|
|
USE(id);
|
2013-09-03 12:43:08 +00:00
|
|
|
const intptr_t kEventSize = sizeof(FILE_NOTIFY_INFORMATION);
|
2013-12-04 10:35:00 +00:00
|
|
|
DirectoryWatchHandle* dir = reinterpret_cast<DirectoryWatchHandle*>(path_id);
|
2013-09-03 12:43:08 +00:00
|
|
|
intptr_t available = dir->Available();
|
2020-09-24 16:26:00 +00:00
|
|
|
if (available <= 0) {
|
|
|
|
return Dart_NewList(0);
|
|
|
|
}
|
2013-09-03 12:43:08 +00:00
|
|
|
intptr_t max_count = available / kEventSize + 1;
|
|
|
|
Dart_Handle events = Dart_NewList(max_count);
|
2016-03-14 18:08:52 +00:00
|
|
|
uint8_t* buffer = Dart_ScopeAllocate(available);
|
2013-09-03 12:43:08 +00:00
|
|
|
intptr_t bytes = dir->Read(buffer, available);
|
|
|
|
intptr_t offset = 0;
|
|
|
|
intptr_t i = 0;
|
|
|
|
while (offset < bytes) {
|
|
|
|
FILE_NOTIFY_INFORMATION* e =
|
|
|
|
reinterpret_cast<FILE_NOTIFY_INFORMATION*>(buffer + offset);
|
|
|
|
|
2013-12-04 10:35:00 +00:00
|
|
|
Dart_Handle event = Dart_NewList(5);
|
2013-09-03 12:43:08 +00:00
|
|
|
int mask = 0;
|
2016-03-16 17:01:00 +00:00
|
|
|
if (e->Action == FILE_ACTION_ADDED) {
|
|
|
|
mask |= kCreate;
|
|
|
|
}
|
|
|
|
if (e->Action == FILE_ACTION_REMOVED) {
|
|
|
|
mask |= kDelete;
|
|
|
|
}
|
|
|
|
if (e->Action == FILE_ACTION_MODIFIED) {
|
|
|
|
mask |= kModifyContent;
|
|
|
|
}
|
|
|
|
if (e->Action == FILE_ACTION_RENAMED_OLD_NAME) {
|
|
|
|
mask |= kMove;
|
|
|
|
}
|
|
|
|
if (e->Action == FILE_ACTION_RENAMED_NEW_NAME) {
|
|
|
|
mask |= kMove;
|
|
|
|
}
|
2013-09-03 12:43:08 +00:00
|
|
|
Dart_ListSetAt(event, 0, Dart_NewInteger(mask));
|
|
|
|
// Move events come in pairs. Just 'enable' by default.
|
|
|
|
Dart_ListSetAt(event, 1, Dart_NewInteger(1));
|
2017-07-13 15:08:33 +00:00
|
|
|
Dart_ListSetAt(
|
|
|
|
event, 2,
|
|
|
|
Dart_NewStringFromUTF16(reinterpret_cast<uint16_t*>(e->FileName),
|
|
|
|
e->FileNameLength / 2));
|
2013-10-28 12:07:46 +00:00
|
|
|
Dart_ListSetAt(event, 3, Dart_NewBoolean(true));
|
2013-12-04 10:35:00 +00:00
|
|
|
Dart_ListSetAt(event, 4, Dart_NewInteger(path_id));
|
2013-09-03 12:43:08 +00:00
|
|
|
Dart_ListSetAt(events, i, event);
|
|
|
|
i++;
|
2016-03-16 17:01:00 +00:00
|
|
|
if (e->NextEntryOffset == 0) {
|
|
|
|
break;
|
|
|
|
}
|
2013-09-03 12:43:08 +00:00
|
|
|
offset += e->NextEntryOffset;
|
|
|
|
}
|
|
|
|
return events;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace bin
|
|
|
|
} // namespace dart
|
|
|
|
|
2021-07-02 19:06:45 +00:00
|
|
|
#endif // defined(DART_HOST_OS_WINDOWS)
|