mirror of
https://github.com/dart-lang/sdk
synced 2024-10-06 16:00:45 +00:00
[vm/ffi] Support Windows 64 bit
Enables dart:ffi on Windows 64 bit. Note that function_stress_test.dart fails in two different ways, these are known bugs. https://github.com/dart-lang/sdk/issues/36138 Closes: https://github.com/dart-lang/sdk/issues/35771 Change-Id: I73012123f2bd90b737fdc1c87c9a9630c20d5660 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/95647 Commit-Queue: Daco Harkes <dacoharkes@google.com> Reviewed-by: Samir Jindel <sjindel@google.com> Reviewed-by: Martin Kustermann <kustermann@google.com>
This commit is contained in:
parent
469da726d6
commit
7f812dea1a
|
@ -4,13 +4,17 @@
|
|||
|
||||
// This file contains test functions for the dart:ffi test cases.
|
||||
|
||||
// The tests which use this don't run on Windows yet.
|
||||
#if !defined(_WIN32)
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdlib.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "platform/globals.h"
|
||||
#if defined(HOST_OS_WINDOWS)
|
||||
#include <psapi.h>
|
||||
#else
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
#include <iostream>
|
||||
#include <limits>
|
||||
|
||||
|
@ -406,6 +410,7 @@ DART_EXPORT void* SmallPointer() {
|
|||
return reinterpret_cast<void*>(-0x80000000L);
|
||||
}
|
||||
|
||||
#if !defined(_WIN32)
|
||||
DART_EXPORT int RedirectStderr() {
|
||||
char filename[256];
|
||||
snprintf(filename, sizeof(filename), "/tmp/captured_stderr_%d", getpid());
|
||||
|
@ -413,7 +418,6 @@ DART_EXPORT int RedirectStderr() {
|
|||
printf("Got file %s\n", filename);
|
||||
return getpid();
|
||||
}
|
||||
#endif
|
||||
|
||||
} // namespace dart
|
||||
|
||||
#endif
|
||||
|
|
|
@ -500,9 +500,9 @@ static RawCode* TrampolineCode(const Function& function,
|
|||
#elif !defined(TARGET_ARCH_X64)
|
||||
// https://github.com/dart-lang/sdk/issues/35774
|
||||
UNREACHABLE();
|
||||
#elif !defined(TARGET_OS_LINUX) && !defined(TARGET_OS_MACOS)
|
||||
#elif !defined(TARGET_OS_LINUX) && !defined(TARGET_OS_MACOS) && \
|
||||
!defined(TARGET_OS_WINDOWS)
|
||||
// https://github.com/dart-lang/sdk/issues/35760 Arm32 && Android
|
||||
// https://github.com/dart-lang/sdk/issues/35771 Windows
|
||||
// https://github.com/dart-lang/sdk/issues/35772 Arm64
|
||||
// https://github.com/dart-lang/sdk/issues/35773 DBC
|
||||
UNREACHABLE();
|
||||
|
@ -588,9 +588,9 @@ static void* GenerateFfiInverseTrampoline(const Function& signature,
|
|||
#elif !defined(TARGET_ARCH_X64)
|
||||
// https://github.com/dart-lang/sdk/issues/35774
|
||||
UNREACHABLE();
|
||||
#elif !defined(TARGET_OS_LINUX) && !defined(TARGET_OS_MACOS)
|
||||
#elif !defined(TARGET_OS_LINUX) && !defined(TARGET_OS_MACOS) && \
|
||||
!defined(TARGET_OS_WINDOWS)
|
||||
// https://github.com/dart-lang/sdk/issues/35760 Arm32 && Android
|
||||
// https://github.com/dart-lang/sdk/issues/35771 Windows
|
||||
// https://github.com/dart-lang/sdk/issues/35772 Arm64
|
||||
// https://github.com/dart-lang/sdk/issues/35773 DBC
|
||||
UNREACHABLE();
|
||||
|
|
|
@ -3,12 +3,12 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
#if !defined(TARGET_OS_LINUX) && !defined(TARGET_OS_MACOS)
|
||||
// TODO(dacoharkes): implement dynamic libraries for other targets.
|
||||
// see
|
||||
// - runtime/vm/native_symbol.h
|
||||
// - runtime/vm/native_symbol_linux.cc
|
||||
// - runtime/bin/extensions.h (but we cannot import from bin)
|
||||
// TODO(dacoharkes): Implement dynamic libraries for other targets & merge the
|
||||
// implementation with:
|
||||
// - runtime/bin/extensions.h
|
||||
// - runtime/bin/extensions_linux.cc
|
||||
// TODO(dacoharkes): Make the code from bin available in a manner similar to
|
||||
// runtime/vm/dart.h Dart_FileReadCallback.
|
||||
#else
|
||||
#include <dlfcn.h>
|
||||
#endif
|
||||
|
@ -19,29 +19,81 @@
|
|||
|
||||
namespace dart {
|
||||
|
||||
DEFINE_NATIVE_ENTRY(Ffi_dl_open, 0, 1) {
|
||||
#if !defined(TARGET_OS_LINUX) && !defined(TARGET_OS_MACOS)
|
||||
UNREACHABLE();
|
||||
#else
|
||||
GET_NON_NULL_NATIVE_ARGUMENT(String, lib_path, arguments->NativeArgAt(0));
|
||||
|
||||
dlerror(); // Clear any errors.
|
||||
void* handle = dlopen(lib_path.ToCString(), RTLD_LAZY);
|
||||
static void* LoadExtensionLibrary(const char* library_file) {
|
||||
#if defined(TARGET_OS_LINUX) || defined(TARGET_OS_MACOS)
|
||||
void* handle = dlopen(library_file, RTLD_LAZY);
|
||||
if (handle == nullptr) {
|
||||
char* error = dlerror();
|
||||
const String& msg = String::Handle(
|
||||
String::NewFormatted("Failed to load dynamic library(%s)", error));
|
||||
String::NewFormatted("Failed to load dynamic library (%s)", error));
|
||||
Exceptions::ThrowArgumentError(msg);
|
||||
}
|
||||
|
||||
return handle;
|
||||
#elif defined(TARGET_OS_WINDOWS)
|
||||
SetLastError(0); // Clear any errors.
|
||||
|
||||
// Convert to wchar_t string.
|
||||
const int name_len =
|
||||
MultiByteToWideChar(CP_UTF8, 0, library_file, -1, NULL, 0);
|
||||
wchar_t* name = new wchar_t[name_len];
|
||||
MultiByteToWideChar(CP_UTF8, 0, library_file, -1, name, name_len);
|
||||
|
||||
void* ext = LoadLibraryW(name);
|
||||
delete[] name;
|
||||
|
||||
if (ext == nullptr) {
|
||||
const int error = GetLastError();
|
||||
const String& msg = String::Handle(
|
||||
String::NewFormatted("Failed to load dynamic library (%i)", error));
|
||||
Exceptions::ThrowArgumentError(msg);
|
||||
}
|
||||
|
||||
return ext;
|
||||
#else
|
||||
const auto& message =
|
||||
String::Handle("The dart:ffi library is not available on this platform.");
|
||||
Exceptions::ThrowByType(Exceptions::kUnsupported, message);
|
||||
#endif
|
||||
}
|
||||
|
||||
DEFINE_NATIVE_ENTRY(Ffi_dl_open, 0, 1) {
|
||||
GET_NON_NULL_NATIVE_ARGUMENT(String, lib_path, arguments->NativeArgAt(0));
|
||||
|
||||
void* handle = LoadExtensionLibrary(lib_path.ToCString());
|
||||
|
||||
return DynamicLibrary::New(handle);
|
||||
}
|
||||
|
||||
static void* ResolveSymbol(void* handle, const char* symbol) {
|
||||
#if defined(TARGET_OS_LINUX) || defined(TARGET_OS_MACOS)
|
||||
dlerror(); // Clear any errors.
|
||||
void* pointer = dlsym(handle, symbol);
|
||||
if (pointer == nullptr) {
|
||||
char* error = dlerror();
|
||||
const String& msg = String::Handle(
|
||||
String::NewFormatted("Failed to lookup symbol (%s)", error));
|
||||
Exceptions::ThrowArgumentError(msg);
|
||||
}
|
||||
return pointer;
|
||||
#elif defined(TARGET_OS_WINDOWS)
|
||||
SetLastError(0);
|
||||
void* pointer = GetProcAddress(reinterpret_cast<HMODULE>(handle), symbol);
|
||||
if (pointer == nullptr) {
|
||||
const int error = GetLastError();
|
||||
const String& msg = String::Handle(
|
||||
String::NewFormatted("Failed to lookup symbol (%i)", error));
|
||||
Exceptions::ThrowArgumentError(msg);
|
||||
}
|
||||
return pointer;
|
||||
#else
|
||||
const auto& message =
|
||||
String::Handle("The dart:ffi library is not available on this platform.");
|
||||
Exceptions::ThrowByType(Exceptions::kUnsupported, message);
|
||||
#endif
|
||||
}
|
||||
|
||||
DEFINE_NATIVE_ENTRY(Ffi_dl_lookup, 1, 2) {
|
||||
#if !defined(TARGET_OS_LINUX) && !defined(TARGET_OS_MACOS)
|
||||
UNREACHABLE();
|
||||
#else
|
||||
GET_NATIVE_TYPE_ARGUMENT(type_arg, arguments->NativeTypeArgAt(0));
|
||||
|
||||
GET_NON_NULL_NATIVE_ARGUMENT(DynamicLibrary, dlib, arguments->NativeArgAt(0));
|
||||
|
@ -50,22 +102,14 @@ DEFINE_NATIVE_ENTRY(Ffi_dl_lookup, 1, 2) {
|
|||
|
||||
void* handle = dlib.GetHandle();
|
||||
|
||||
dlerror(); // Clear any errors.
|
||||
intptr_t pointer =
|
||||
reinterpret_cast<intptr_t>(dlsym(handle, argSymbolName.ToCString()));
|
||||
char* error;
|
||||
if ((error = dlerror()) != NULL) {
|
||||
const String& msg = String::Handle(
|
||||
String::NewFormatted("Failed to lookup symbol (%s)", error));
|
||||
Exceptions::ThrowArgumentError(msg);
|
||||
}
|
||||
const intptr_t pointer = reinterpret_cast<intptr_t>(
|
||||
ResolveSymbol(handle, argSymbolName.ToCString()));
|
||||
|
||||
// TODO(dacoharkes): should this return NULL if addres is 0?
|
||||
// TODO(dacoharkes): should this return Object::null() if address is 0?
|
||||
// https://github.com/dart-lang/sdk/issues/35756
|
||||
RawPointer* result =
|
||||
Pointer::New(type_arg, Integer::Handle(zone, Integer::New(pointer)));
|
||||
return result;
|
||||
#endif
|
||||
}
|
||||
|
||||
DEFINE_NATIVE_ENTRY(Ffi_dl_getHandle, 0, 1) {
|
||||
|
|
|
@ -300,9 +300,9 @@ class Api : AllStatic {
|
|||
#if !defined(TARGET_ARCH_X64)
|
||||
// https://github.com/dart-lang/sdk/issues/35774
|
||||
return false;
|
||||
#elif !defined(TARGET_OS_LINUX) && !defined(TARGET_OS_MACOS)
|
||||
#elif !defined(TARGET_OS_LINUX) && !defined(TARGET_OS_MACOS) && \
|
||||
!defined(TARGET_OS_WINDOWS)
|
||||
// https://github.com/dart-lang/sdk/issues/35760 Arm32 && Android
|
||||
// https://github.com/dart-lang/sdk/issues/35771 Windows
|
||||
// https://github.com/dart-lang/sdk/issues/35772 Arm64
|
||||
// https://github.com/dart-lang/sdk/issues/35773 DBC
|
||||
return false;
|
||||
|
|
|
@ -9,6 +9,7 @@ String _platformPath(String name, {String path}) {
|
|||
if (path == null) path = "";
|
||||
if (Platform.isLinux) return path + "lib" + name + ".so";
|
||||
if (Platform.isMacOS) return path + "lib" + name + ".dylib";
|
||||
if (Platform.isWindows) return path + name + ".dll";
|
||||
throw Exception("Platform not implemented");
|
||||
}
|
||||
|
||||
|
|
|
@ -9,6 +9,7 @@ String _platformPath(String name, {String path}) {
|
|||
if (path == null) path = "";
|
||||
if (Platform.isLinux) return path + "lib" + name + ".so";
|
||||
if (Platform.isMacOS) return path + "lib" + name + ".dylib";
|
||||
if (Platform.isWindows) return path + name + ".dll";
|
||||
throw Exception("Platform not implemented");
|
||||
}
|
||||
|
||||
|
|
|
@ -32,7 +32,7 @@ test(GCWatcher watcher, void Function() testee,
|
|||
}
|
||||
|
||||
main() async {
|
||||
final watcher = GCWatcher();
|
||||
final watcher = GCWatcher.ifAvailable();
|
||||
try {
|
||||
await test(watcher, testBoxInt64);
|
||||
// On 64-bit platforms this won't trigger GC because the result fits into a
|
||||
|
|
|
@ -3,25 +3,48 @@
|
|||
// BSD-style license that can be found in the LICENSE file.
|
||||
|
||||
import 'dart:io';
|
||||
import 'dart:convert';
|
||||
import 'dylib_utils.dart';
|
||||
import 'dart:ffi';
|
||||
import 'dart:io' show Platform;
|
||||
|
||||
DynamicLibrary ffiTestFunctions = dlopenPlatformSpecific("ffi_test_functions");
|
||||
|
||||
abstract class GCWatcher {
|
||||
factory GCWatcher() => _GCWatcherImpl();
|
||||
factory GCWatcher.dummy() => _MockGCWatcher();
|
||||
factory GCWatcher.ifAvailable() =>
|
||||
Platform.isWindows ? GCWatcher.dummy() : GCWatcher();
|
||||
|
||||
Future<int> size();
|
||||
void dispose();
|
||||
}
|
||||
|
||||
// Requires --verbose-gc.
|
||||
class GCWatcher {
|
||||
class _GCWatcherImpl implements GCWatcher {
|
||||
int _suffix;
|
||||
|
||||
Future<int> size() async {
|
||||
return await File("/tmp/captured_stderr_$_suffix").length();
|
||||
}
|
||||
|
||||
GCWatcher() {
|
||||
_GCWatcherImpl() {
|
||||
print("Starting...");
|
||||
_suffix = ffiTestFunctions
|
||||
.lookupFunction<Int32 Function(), int Function()>("RedirectStderr")();
|
||||
}
|
||||
|
||||
dispose() => File("/tmp/captured_stderr_$_suffix").deleteSync();
|
||||
dispose() {
|
||||
try {
|
||||
File("/tmp/captured_stderr_$_suffix").deleteSync();
|
||||
} catch (e) {
|
||||
print("deleting file failed");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
class _MockGCWatcher implements GCWatcher {
|
||||
int _ctr = 0;
|
||||
|
||||
Future<int> size() async => ++_ctr;
|
||||
dispose() {}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ Future<void> testGC() async {
|
|||
CString cs = ffi.fromAddress<CString>(11);
|
||||
bar = cs;
|
||||
foo = "";
|
||||
final watcher = GCWatcher();
|
||||
final watcher = GCWatcher.ifAvailable();
|
||||
int counts = await watcher.size();
|
||||
for (int i = 0; i < 1000000; ++i) {
|
||||
foo = new X(i);
|
||||
|
|
|
@ -229,8 +229,8 @@ io/socket_many_connections_test: Skip # Timeout
|
|||
io/web_socket_compression_test: Skip # Timeout
|
||||
io/web_socket_test: Skip # Timeout
|
||||
|
||||
[ $arch != x64 || $compiler != dartk || $mode == product || $system != linux && $system != macos]
|
||||
ffi/function_stress_test: SkipByDesign # FFI must be supported. Also requires --verbose-gc, which isn't included in product.
|
||||
[ $arch != x64 || $compiler != dartk || $mode == product || $system != linux && $system != macos ]
|
||||
ffi/function_stress_test: SkipByDesign # FFI must be supported. Also requires --verbose-gc, which isn't included in product. Windows issues will be fixed in IL CL: https://github.com/dart-lang/sdk/issues/36138
|
||||
ffi/subtype_test: SkipByDesign # FFI must be supported. Also requires --verbose-gc, which isn't included in product.
|
||||
|
||||
[ $mode == product || $mode != product ]
|
||||
|
|
|
@ -133,5 +133,5 @@ full_coverage_test: Skip # TODO(vegorov) SIMDBC interpreter doesn't support cove
|
|||
link_natives_lazily_test: SkipByDesign # SIMDBC interpreter doesn't support lazy linking of natives.
|
||||
no_lazy_dispatchers_test: SkipByDesign # SIMDBC interpreter doesn't support --no_lazy_dispatchers
|
||||
|
||||
[ $arch != x64 || $system != linux && $system != macos ]
|
||||
[ $arch != x64 || $system != linux && $system != macos && $system != windows ]
|
||||
ffi: Skip # ffi not yet supported on other systems than linux/macos 64
|
||||
|
|
Loading…
Reference in a new issue