The magic number has the opposite endianness on the arm64 macs.
TEST=locally verified + SDK build
Closes: https://github.com/dart-lang/sdk/issues/54796
Change-Id: I4a66f44e0a32fbc3530bda6ffca177ba14d9dca7
Cq-Include-Trybots: luci.dart.try:vm-aot-mac-release-arm64-try,vm-mac-debug-arm64-try,dart-sdk-mac-arm64-try,pkg-mac-release-arm64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/349661
Reviewed-by: Martin Kustermann <kustermann@google.com>
running in the JIT VM
TEST=new test added
Bug:54528
Change-Id: Ifa0176ee453e5af4e45bb0b74cf9ac9ba23fb93e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/346060
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Siva Annamalai <asiva@google.com>
This reverts: https://dart-review.googlesource.com/c/sdk/+/338620
We'd like to support this use case with a different API. See the
discussion in https://github.com/dart-lang/sdk/issues/54739.
TEST=tests/ffi
Bug: https://github.com/dart-lang/sdk/issues/44589
Bug: https://github.com/dart-lang/sdk/issues/54771
Change-Id: Ic22fbcab14d374bb9c81bba1f1bf6ae2dfc9e674
Cq-Include-Trybots: luci.dart.try:vm-aot-android-release-arm64c-try,vm-aot-android-release-arm_x64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-debug-x64c-try,vm-aot-mac-release-arm64-try,vm-aot-mac-release-x64-try,vm-aot-obfuscate-linux-release-x64-try,vm-aot-optimization-level-linux-release-x64-try,vm-aot-win-debug-arm64-try,vm-aot-win-debug-x64c-try,vm-aot-win-release-x64-try,vm-appjit-linux-debug-x64-try,vm-asan-linux-release-x64-try,vm-checked-mac-release-arm64-try,vm-eager-optimization-linux-release-ia32-try,vm-eager-optimization-linux-release-x64-try,vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64c-try,vm-ffi-qemu-linux-release-arm-try,vm-ffi-qemu-linux-release-riscv64-try,vm-fuchsia-release-x64-try,vm-kernel-linux-debug-x64-try,vm-kernel-precomp-linux-release-x64-try,vm-linux-debug-ia32-try,vm-linux-debug-x64-try,vm-linux-debug-x64c-try,vm-mac-debug-arm64-try,vm-mac-debug-x64-try,vm-msan-linux-release-x64-try,vm-reload-linux-debug-x64-try,vm-reload-rollback-linux-debug-x64-try,vm-ubsan-linux-release-x64-try,vm-win-debug-arm64-try,vm-win-debug-x64-try,vm-win-debug-x64c-try,vm-win-release-ia32-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/349340
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
mach_absolute_time uses the same clock as CLOCK_UPTIME_RAW. There are privacy concerns that boot time can be used for device fingerprinting. Dart doesn't not need to know boot time, only some monotonic clock.
TEST=ci
Change-Id: I57acd080bb93ce9cf51b4b90aec09bb7cab7f7af
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/348044
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Brian Quinlan <bquinlan@google.com>
Previously they were built with TARGET_OS_FUCHSIA regardless of target OS.
TEST=ci
Change-Id: I53e95bb61c3926334e861ed56ceb3ea018e7bf1a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/347202
Commit-Queue: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
This change fixes the following 2 bugs related to unwinding records
on Windows:
1) When cross-compiling from another OS to Windows, unwinding records
were not added to the end of the code section. Later, when loading
AOT snapshot, arbitrary bytes at the end of the code section were
used as the unwinding data, which could result in the errors
returned from Windows API calls.
2) When code section is mapped, its size was rounded up to the page
size; when looking for unwinding record, size of the unwinding
record was subtracted from the rounded size. This is not correct
as unwinding record is placed right at the end of code section,
so code section size should be used before rounding.
Also, magic value is added to the unwinding record in order to
verify that it is preserved and correctly found.
TEST=Manually tested repro from b/320642692
TEST=ffi/ffi_induce_a_crash_test
Fixes b/320642692
Fixes https://github.com/dart-lang/sdk/issues/54206
Change-Id: Id0c6413cd1b759da9e9f25f7617eef55f33b04a2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/346940
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
I/O can take arbitrarily long, and open interior pointers prevent all other isolates in the group to reaching safepoints.
TEST=ci
Bug: https://github.com/flutter/flutter/issues/140763
Change-Id: I1fa732d0db31500946aee232dc31f5baf324a55e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/345746
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Brian Quinlan <bquinlan@google.com>
On WSL 1 trying to allocate memory close to the binary
by supplying a hint fails with ENOMEM for unclear reason.
Some reports suggest that this might be related to the
alignment of the hint but aligning it by 64Kb does not
make the issue go away in our experiments. Instead
just retry without any hint.
Fixes https://github.com/dart-lang/sdk/issues/54587
TEST=manually under WSL 1
Change-Id: I0adf997fbf76e470a57da00f5ce7a26bb50706f7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/345802
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
No one could remember why this code was in a separate repo, and
checking it in to the SDK repo will make eliminating the
flutter buildroot repo a tiny bit easier.
TEST=It builds.
Change-Id: Ia34ca0c284fee1dd1734f45ef7acb9dd5cde808c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/342083
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Reviewed-by: Brian Quinlan <bquinlan@google.com>
Fields used in Dart test with `@Native` fields must be `extern "C"` to
avoid name mangling.
As seen from build and test failures, MSVC doesn't seem to consistently
use C fields for `extern "C"` fields defined in a C++ file.
By moving these fields into a C file, they can be referenced both from
the other C++ test functions and via Dart fields.
TEST=Windows CI build
Cq-Include-Trybots: luci.dart.try:vm-win-debug-x64-try,vm-win-debug-x64c-try,vm-aot-win-debug-x64c-try
Change-Id: Ia504a1d6e04efd00bdd50de54f4b65292ec7a41a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/342260
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Hossein Yousefi <yousefi@google.com>
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Allow annotating top-level or static fields with `@Native` to create
fields backed by native memory.
By using the `_addressOf` operator implemented in the VM, these fields
can be implemented in the CFE by replacing them with accessors looking
up the pointer and then using existing methods to load and store the
value.
Closes https://github.com/dart-lang/sdk/issues/50551
TEST=tests/ffi/native_assets/asset_*_test.dart
TEST=pkg/analyzer/test/src/diagnostics/ffi_native_test.dart
CoreLibraryReviewExempt: VM & dart2wasm only feature
Change-Id: I61dccc88076723d6a6ba02d7fd848b18e4caf780
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/338020
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Brian Wilkerson <brianwilkerson@google.com>
Reviewed-by: Lasse Nielsen <lrn@google.com>
Reviewed-by: Chloe Stefantsova <cstefantsova@google.com>
Enables passing inner pointers to typed data in FFI leaf calls.
This works for typed data's in the Dart heap, external typed datas
(constructed from `Pointer.asTypedList`), and typed data views.
Notable implementation details:
1. The Dart signature is used in the Marshaller now. This means it
needs to keep track of whether there's a pointer argument in the
signature (`asFunction`) or not (`@Native`).
2. Unwrapping is done in `FfiCallInstr::EmitNativeCode` before moving
the arguments to their native location. This ensures we can use
the assembler logic to load the `TypedDataBase::data` field.
3. The `XXXList` user visible classes don't have predefined cids.
So the implementation uses symbols for comparison.
4. The type checking logic takes `isLeaf` as input to reject typed
data. This leads to an error message about the type not accepted.
Alternatively, we could consider adding an error message that
specifically says the function should be leaf.
5. To cover all calling convention variants, tests are generated with
up to 20 arguments.
TEST=pkg/analyzer/test/src/diagnostics/ffi_unwrap_typed_data_test.dart
TEST=tests/ffi/unwrap_typeddata_generated_native_test.dart
TEST=tests/ffi/unwrap_typeddata_generated_test.dart
TEST=tests/ffi/vmspecific_static_checks_typeddata_test.dart
Closes: https://github.com/dart-lang/sdk/issues/44589
Change-Id: Ia78f18bf3238d42ac6882929b441f6dc432fcefe
Cq-Include-Trybots: luci.dart.try:vm-aot-android-release-arm64c-try,vm-aot-android-release-arm_x64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-debug-x64c-try,vm-aot-mac-release-arm64-try,vm-aot-mac-release-x64-try,vm-aot-obfuscate-linux-release-x64-try,vm-aot-optimization-level-linux-release-x64-try,vm-aot-win-debug-arm64-try,vm-aot-win-debug-x64c-try,vm-aot-win-release-x64-try,vm-appjit-linux-debug-x64-try,vm-asan-linux-release-x64-try,vm-checked-mac-release-arm64-try,vm-eager-optimization-linux-release-ia32-try,vm-eager-optimization-linux-release-x64-try,vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64c-try,vm-ffi-qemu-linux-release-arm-try,vm-ffi-qemu-linux-release-riscv64-try,vm-fuchsia-release-x64-try,vm-kernel-linux-debug-x64-try,vm-kernel-precomp-linux-release-x64-try,vm-linux-debug-ia32-try,vm-linux-debug-x64-try,vm-linux-debug-x64c-try,vm-mac-debug-arm64-try,vm-mac-debug-x64-try,vm-msan-linux-release-x64-try,vm-reload-linux-debug-x64-try,vm-reload-rollback-linux-debug-x64-try,vm-ubsan-linux-release-x64-try,vm-win-debug-arm64-try,vm-win-debug-x64-try,vm-win-debug-x64c-try,vm-win-release-ia32-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/338620
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Currently crt warn/error/asserts will disappear, so redirecting them to stderr sounds like a better approach.
TEST=manual win run
Change-Id: Iee0a2effd93fbe104dbeab77abebc54beaecb5dc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/340583
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
- Fixes new AOT snapshots in the SDK failing with SIGILL in ARM environments that don't support the integer division instructions.
- Likewise fixes snapshot generated by `dart compile exe`.
TEST=local QEMU
Bug: https://github.com/dart-lang/sdk/issues/54198
Change-Id: Ifb998ced4e900a64ef02a464903a50954f6e0699
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/339104
Reviewed-by: Ben Konyi <bkonyi@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Adds tests to cover constant values flowing into `Handle` parameters
of `@Native external` functions.
The first test is a repro of the failure from
https://dart-review.googlesource.com/c/sdk/+/333840
The other tests construct more extreme cases.
Handles can't be passed to leaf functions, so no `isLeaf`.
Split off reland:
https://dart-review.googlesource.com/c/sdk/+/333841
TEST=tests/ffi/ffi_native_handles_test.dart
Change-Id: I89d31a940f5a63793a03a9eb364231a54164a328
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/336661
Reviewed-by: Tess Strickland <sstrickl@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
Auto-Submit: Daco Harkes <dacoharkes@google.com>
Switch the Windows ARM64 builds to use MSVC. Clang disagrees with itself about handling of small structs in variadic functions, allowing splitting between the last argument register and the stack as the callee but not as the caller.
TEST=ci
Cq-Include-Trybots: luci.dart.try:vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64c-try,vm-ffi-android-release-arm-try,vm-ffi-android-release-arm64c-try,vm-ffi-qemu-linux-release-arm-try,vm-linux-release-arm64-try,vm-mac-debug-arm64-try,vm-mac-release-arm64-try,vm-win-debug-arm64-try,vm-win-release-arm64-try,vm-ffi-qemu-linux-release-riscv64-try,vm-linux-debug-ia32-try,vm-linux-release-ia32-try,vm-win-release-ia32-try,vm-linux-debug-x64-try,vm-linux-release-x64-try,vm-mac-debug-x64-try,vm-mac-release-x64-try,vm-win-debug-x64-try,vm-win-release-x64-try
Bug: https://github.com/dart-lang/sdk/issues/52644
Bug: https://github.com/dart-lang/sdk/issues/53829
Change-Id: I2fd6c40620a885479f11bb8528ca1e9df3948a2f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/331209
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
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>
build/fuchsia/gn-sdk is a copy of the current GN SDK with paths adjusted.
The rest of build/fuchsia comes from Flutter.
TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/38752
Change-Id: I192cca955d05991bde3931d053df9835c5a2195d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/334142
Reviewed-by: Zijie He <zijiehe@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Thomas <athom@google.com>
Unmapped page can get back to us with previously added, not yet deleted unwinding instructions, so attempt to add them again will fail.
Fixes https://github.com/dart-lang/sdk/issues/53943
TEST=ci
Change-Id: Ie3b61f3d5249d5a9795072d795d913182039142a
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/333900
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Build one package with three elf_test_runner components: one for each of the binaries that the test harness invokes on the target. (Though currently only tests that use "dart" are setup.)
Create includable CML shards for the capabilites required by the AOT and JIT VMs.
Fold test_runner's fuchsia_cfv2.dart back into fuchsia.dart.
TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/38752
Change-Id: I7bd8d43d184cbcb11903c7aed77ce31fb30cb894
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/332451
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Zijie He <zijiehe@google.com>
Reviewed-by: Alexander Thomas <athom@google.com>
This fixes an edge case on all ARM64 ABIs, when there is only one argument register remaining and the next argument is a 9-16 byte struct.
TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/52644
Change-Id: I40d962e6d1b3484dbfcf91f5d6baca0bfec76056
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/330161
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
The `gen_snapshot` binary passes `--link_natives_lazily` if
it generates AppJIT/AOT snapshots (see `runtime/bin/gen_snapshot.cc`)
=> The `dart` binary should do so as well.
TEST=ci
Change-Id: I88d69f73a38cb23d4f7482739e2e0fda3c65ecef
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/330760
Commit-Queue: Martin Kustermann <kustermann@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>