dart-sdk/runtime/bin
Daco Harkes b113fffb65 Reland "[vm/ffi] Throw on returning Error in Handle"
Fix: Check handle contents for Smi.
Closes: https://github.com/flutter/flutter/issues/112726

Orignal CL description:

Makes `Dart_Handle` FFI returns behave as the following snippet:

```
Dart_Handle ExampleSnippet() {
  Dart_Handle result = ...;
  if (Dart_IsError(result)) {
    Dart_PropagateError(result);
  }
  return result;
}
```

Also makes FFI consistent with Dart_NativeFunctions, which will
automatically throw upon return if Dart_SetReturnValue set the result
to an error.

`UnhandledExceptions` cannot flow out into Dart generated code. So,
the implementation needs to be in `FfiCallInstr::EmitNativeCode`.

Using `Dart_IsError` is slow compared to a machine code class id
check. So, we should do the handle unwrapping and class id check in
machine code.

Unwrapping Handles in machine code is only safe when the GC is
guaranteed to not run: Either (1) in `kThreadInGenerated`, or (2) in
`kThreadInNative`, but only when transitioned into safepoint. So, the
handle cannot be unwrapped immediately after the FFI call in machine code. We first need to transition back to generated.

This means we need to transition again to native to do the actual
`Dart_PropagateError` call. We can do so without the stub in JIT
because we never return with normal control flow.

Performance impact of this change is within benchmark noise in both
JIT and AOT.
Size impact is 42 bytes on x64, which is 10% in AOT and 12% in JIT.

For more numbers see: go/dart-ffi-handle-error

TEST=runtime/bin/ffi_test/ffi_test_functions_vmspecific.cc
TEST=tests/ffi/vmspecific_handle_test.dart

Closes: https://github.com/dart-lang/sdk/issues/49936
Change-Id: Id8edfd841a7d6246438386007d83747868a0a151
Cq-Include-Trybots: luci.dart.try:vm-canary-linux-debug-try,vm-ffi-android-debug-arm64c-try,vm-ffi-android-debug-arm-try,vm-kernel-gcc-linux-try,vm-kernel-linux-debug-x64-try,vm-kernel-linux-debug-x64c-try,vm-kernel-msvc-windows-try,vm-kernel-optcounter-threshold-linux-release-x64-try,vm-kernel-precomp-asan-linux-release-x64-try,vm-kernel-precomp-linux-debug-x64-try,vm-kernel-reload-linux-debug-x64-try,vm-kernel-reload-rollback-linux-debug-x64-try,vm-kernel-tsan-linux-release-x64-try,vm-kernel-win-debug-x64-try,vm-kernel-win-debug-ia32-try,vm-precomp-ffi-qemu-linux-release-arm-try,vm-precomp-ffi-qemu-linux-release-riscv64-try,vm-kernel-linux-debug-ia32-try,vm-kernel-mac-release-arm64-try,vm-kernel-precomp-win-debug-x64c-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/262342
Reviewed-by: Martin Kustermann <kustermann@google.com>
Auto-Submit: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
2022-10-03 12:25:08 +00:00
..
ffi_test Reland "[vm/ffi] Throw on returning Error in Handle" 2022-10-03 12:25:08 +00:00
ffi_unit_test [vm/ffi] Add Fuchsia ABI unit tests 2022-08-16 12:17:26 +00:00
abstract_socket_test.cc
address_sanitizer.cc
analyze_snapshot.cc Updates to analyze_snapshot tool 2022-08-23 12:18:00 +00:00
BUILD.gn [vm/ffi] Support DynamicLibrary.process() on Windows 2022-09-27 08:42:03 +00:00
builtin.cc
builtin.h
builtin_gen_snapshot.cc
builtin_impl_sources.gni
builtin_in.cc
builtin_natives.cc
builtin_sources.gni
cli.cc
cli_impl_sources.gni
cli_sources.gni
console.h
console_posix.cc [io] Don't restore terminal state on exit. 2022-05-31 15:36:33 +00:00
console_win.cc [io] Don't restore terminal state on exit. 2022-05-31 15:36:33 +00:00
crashpad.cc
crashpad.h
crypto.cc
crypto.h
crypto_android.cc
crypto_fuchsia.cc
crypto_linux.cc
crypto_macos.cc
crypto_test.cc
crypto_win.cc
dart_embedder_api_impl.cc
dart_io_api_impl.cc [dart:io] Publish implementations of the VM file callbacks. 2022-04-19 23:27:17 +00:00
dartdev_isolate.cc Fix typos 2022-06-15 11:08:28 +00:00
dartdev_isolate.h
dartutils.cc [VM/Runtime] - Use 'const' qualifier for CObject typed data 2022-09-13 22:38:22 +00:00
dartutils.h [VM/Runtime] - Use 'const' qualifier for CObject typed data 2022-09-13 22:38:22 +00:00
dfe.cc Fix typos 2022-06-15 11:08:28 +00:00
dfe.h
directory.cc
directory.h
directory_android.cc Fix typos 2022-07-12 19:35:22 +00:00
directory_fuchsia.cc Fix typos 2022-07-12 19:35:22 +00:00
directory_linux.cc Fix typos 2022-07-12 19:35:22 +00:00
directory_macos.cc Fix typos 2022-07-12 19:35:22 +00:00
directory_test.cc
directory_win.cc
elf_loader.cc
elf_loader.h
entrypoints_verification_test.cc
error_exit.cc
error_exit.h
eventhandler.cc
eventhandler.h
eventhandler_android.cc
eventhandler_android.h
eventhandler_fuchsia.cc
eventhandler_fuchsia.h
eventhandler_linux.cc
eventhandler_linux.h
eventhandler_macos.cc
eventhandler_macos.h
eventhandler_test.cc
eventhandler_win.cc
eventhandler_win.h
exe_utils.cc
exe_utils.h
fdutils.h
fdutils_android.cc
fdutils_fuchsia.cc
fdutils_linux.cc
fdutils_macos.cc
file.cc [VM/Runtime] - Use 'const' qualifier for CObject typed data 2022-09-13 22:38:22 +00:00
file.h Implement anonymous pipes and the ability to transmit them between processes using Unix Domain Sockets. 2022-09-13 21:16:28 +00:00
file_android.cc Implement anonymous pipes and the ability to transmit them between processes using Unix Domain Sockets. 2022-09-13 21:16:28 +00:00
file_fuchsia.cc Implement anonymous pipes and the ability to transmit them between processes using Unix Domain Sockets. 2022-09-13 21:16:28 +00:00
file_linux.cc Implement anonymous pipes and the ability to transmit them between processes using Unix Domain Sockets. 2022-09-13 21:16:28 +00:00
file_macos.cc Implement anonymous pipes and the ability to transmit them between processes using Unix Domain Sockets. 2022-09-13 21:16:28 +00:00
file_support.cc
file_system_watcher.cc
file_system_watcher.h
file_system_watcher_android.cc
file_system_watcher_fuchsia.cc
file_system_watcher_linux.cc
file_system_watcher_macos.cc
file_system_watcher_win.cc
file_test.cc
file_win.cc [gardening] Fix gen_snapshot crash on msvc. 2022-09-21 18:16:56 +00:00
file_win.h
filter.cc
filter.h
gen_snapshot.cc [standalone] Remove RISC-V linker hack. 2022-06-30 21:16:04 +00:00
gzip.cc
gzip.h
hashmap_test.cc
ifaddrs-android.cc
ifaddrs-android.h
io_buffer.cc
io_buffer.h
io_impl_sources.gni Add support for sending file descriptors over unix domain sockets on macOS 2022-09-01 20:36:12 +00:00
io_natives.cc Implement anonymous pipes and the ability to transmit them between processes using Unix Domain Sockets. 2022-09-13 21:16:28 +00:00
io_natives.h
io_service.cc
io_service.h Implement anonymous pipes and the ability to transmit them between processes using Unix Domain Sockets. 2022-09-13 21:16:28 +00:00
io_service_no_ssl.cc
io_service_no_ssl.h
io_sources.gni
isolate_data.cc
isolate_data.h
loader.cc
loader.h
lockers.h
main.cc [standalone] Cleanup sorting classes before generating an AppJIT snapshot. 2022-08-11 20:58:39 +00:00
main_options.cc [ Service / Timeline ] Enable Compiler, Dart, and GC timeline streams when --observe is provided 2022-08-15 21:02:36 +00:00
main_options.h
namespace.cc
namespace.h
namespace_android.cc
namespace_fuchsia.cc
namespace_fuchsia.h
namespace_linux.cc
namespace_macos.cc
namespace_win.cc
observatory_assets_empty.cc
options.cc
options.h
platform.cc
platform.h [vm] Add OS and architecture to non-symbolic stack traces. 2022-08-05 11:53:37 +00:00
platform_android.cc [vm] Add OS and architecture to non-symbolic stack traces. 2022-08-05 11:53:37 +00:00
platform_fuchsia.cc [vm] Add OS and architecture to non-symbolic stack traces. 2022-08-05 11:53:37 +00:00
platform_linux.cc [vm] Add OS and architecture to non-symbolic stack traces. 2022-08-05 11:53:37 +00:00
platform_macos.cc [vm] Add OS and architecture to non-symbolic stack traces. 2022-08-05 11:53:37 +00:00
platform_macos.h
platform_macos_cocoa.h
platform_macos_cocoa.mm
platform_win.cc [vm] Add OS and architecture to non-symbolic stack traces. 2022-08-05 11:53:37 +00:00
priority_heap_test.cc
process.cc Generate an error when starting Processes on iOS 2022-08-29 17:14:36 +00:00
process.h
process_android.cc [vm] Avoid deadlocks when launching subprocesses 2022-04-20 13:55:59 +00:00
process_fuchsia.cc
process_linux.cc [vm] Avoid deadlocks when launching subprocesses 2022-04-20 13:55:59 +00:00
process_macos.cc [vm] Avoid deadlocks when launching subprocesses 2022-04-20 13:55:59 +00:00
process_test.cc
process_win.cc
reference_counting.h
root_certificates_unsupported.cc
run_vm_tests.cc [standalone] Remove RISC-V linker hack. 2022-06-30 21:16:04 +00:00
secure_socket_filter.cc Fix typos 2022-06-15 11:08:28 +00:00
secure_socket_filter.h
secure_socket_unsupported.cc
secure_socket_utils.cc [VM / IO] Fix cases where TlsExceptions were being created with an 2022-04-04 21:57:22 +00:00
secure_socket_utils.h [VM / IO] Fix cases where TlsExceptions were being created with an 2022-04-04 21:57:22 +00:00
secure_socket_utils_test.cc
security_context.cc
security_context.h
security_context_android.cc
security_context_fuchsia.cc
security_context_linux.cc
security_context_macos.cc
security_context_win.cc
snapshot_empty.cc
snapshot_in.cc
snapshot_utils.cc [pkg/dart2native] Avoid overwriting section contents in MachO files. 2022-09-29 08:32:47 +00:00
snapshot_utils.h
snapshot_utils_test.cc [vm/test] Remove checked-in binaries from MachO test. 2022-08-17 16:18:35 +00:00
socket.cc
socket.h
socket_android.cc
socket_base.cc [VM/Runtime] - Use 'const' qualifier for CObject typed data 2022-09-13 22:38:22 +00:00
socket_base.h
socket_base_android.cc
socket_base_android.h
socket_base_fuchsia.cc
socket_base_fuchsia.h
socket_base_linux.cc Add support for sending file descriptors over unix domain sockets on macOS 2022-09-01 20:36:12 +00:00
socket_base_linux.h
socket_base_macos.cc Add support for sending file descriptors over unix domain sockets on macOS 2022-09-01 20:36:12 +00:00
socket_base_macos.h
socket_base_posix.cc Add support for sending file descriptors over unix domain sockets on macOS 2022-09-01 20:36:12 +00:00
socket_base_win.cc
socket_base_win.h
socket_fuchsia.cc
socket_linux.cc
socket_macos.cc
socket_win.cc
stdio.cc [io] Don't restore terminal state on exit. 2022-05-31 15:36:33 +00:00
stdio.h [io] Don't restore terminal state on exit. 2022-05-31 15:36:33 +00:00
stdio_android.cc [io] Don't restore terminal state on exit. 2022-05-31 15:36:33 +00:00
stdio_fuchsia.cc [io] Don't restore terminal state on exit. 2022-05-31 15:36:33 +00:00
stdio_linux.cc [io] Don't restore terminal state on exit. 2022-05-31 15:36:33 +00:00
stdio_macos.cc [io] Don't restore terminal state on exit. 2022-05-31 15:36:33 +00:00
stdio_win.cc [io] Don't restore terminal state on exit. 2022-05-31 15:36:33 +00:00
sync_socket.cc
sync_socket.h
sync_socket_android.cc
sync_socket_fuchsia.cc
sync_socket_linux.cc
sync_socket_macos.cc
sync_socket_win.cc
test_utils.cc
test_utils.h
thread.h
thread_absl.cc
thread_absl.h
thread_android.cc
thread_android.h
thread_fuchsia.cc
thread_fuchsia.h
thread_linux.cc
thread_linux.h
thread_macos.cc
thread_macos.h
thread_win.cc
thread_win.h
typed_data_utils.cc
typed_data_utils.h
utils.cc
utils.h
utils_android.cc
utils_fuchsia.cc
utils_linux.cc
utils_macos.cc
utils_win.cc
utils_win.h
virtual_memory.h
virtual_memory_fuchsia.cc
virtual_memory_posix.cc
virtual_memory_win.cc
vmservice_impl.cc
vmservice_impl.h