[vm, ffi] Fail more gracefully when attempting to use FFI on a simulator.

TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/48846
Bug: https://github.com/dart-lang/sdk/issues/49472
Change-Id: I9083d1c4e2ff633d22747f80ce1fed970e2f771a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/251849
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
This commit is contained in:
Ryan Macnak 2022-07-25 19:29:09 +00:00 committed by Commit Bot
parent 901d01a45c
commit f9e833416e

View file

@ -15,6 +15,34 @@
namespace dart {
#if defined(USING_SIMULATOR)
DART_NORETURN static void SimulatorUnsupported() {
Exceptions::ThrowUnsupportedError(
"Not supported on simulated architectures.");
}
DEFINE_NATIVE_ENTRY(Ffi_dl_open, 0, 1) {
SimulatorUnsupported();
}
DEFINE_NATIVE_ENTRY(Ffi_dl_processLibrary, 0, 0) {
SimulatorUnsupported();
}
DEFINE_NATIVE_ENTRY(Ffi_dl_executableLibrary, 0, 0) {
SimulatorUnsupported();
}
DEFINE_NATIVE_ENTRY(Ffi_dl_lookup, 1, 2) {
SimulatorUnsupported();
}
DEFINE_NATIVE_ENTRY(Ffi_dl_getHandle, 0, 1) {
SimulatorUnsupported();
}
DEFINE_NATIVE_ENTRY(Ffi_dl_providesSymbol, 0, 2) {
SimulatorUnsupported();
}
#else // defined(USING_SIMULATOR)
static void* LoadDynamicLibrary(const char* library_file) {
char* error = nullptr;
void* handle = Utils::LoadDynamicLibrary(library_file, &error);
@ -63,11 +91,8 @@ DEFINE_NATIVE_ENTRY(Ffi_dl_processLibrary, 0, 0) {
defined(DART_HOST_OS_ANDROID) || defined(DART_HOST_OS_FUCHSIA)
return DynamicLibrary::New(RTLD_DEFAULT);
#else
const Array& args = Array::Handle(Array::New(1));
args.SetAt(0,
String::Handle(String::New(
"DynamicLibrary.process is not available on this platform.")));
Exceptions::ThrowByType(Exceptions::kUnsupported, args);
Exceptions::ThrowUnsupportedError(
"DynamicLibrary.process is not available on this platform.");
#endif
}
@ -105,4 +130,6 @@ DEFINE_NATIVE_ENTRY(Ffi_dl_providesSymbol, 0, 2) {
return Bool::Get(SymbolExists(handle, argSymbolName.ToCString())).ptr();
}
#endif // defined(USING_SIMULATOR)
} // namespace dart