Commit Graph

4235 Commits

Author SHA1 Message Date
Ben Konyi e3ca6d824b [ Service ] Add expression evaluation support to dart_runtime_service_vm
Brings pass rate of package:vm_service tests to ~85%

TEST=Manual
Change-Id: I2335d98358362110add93c2acfe51c3fc1385237
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/487560
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
2026-03-16 11:14:52 -07:00
Alexander Aprelev 9bd916646a [infra] Roll clang to d0ddae678e3f634c988542dfbdde1dd0afe66344.
Update clang format, remove boringssl err.h from clang-tidy

TEST=ci
Change-Id: Ib73d89b292ee4dfa2249ec519071e7621bb92c22
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/487885
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2026-03-13 12:34:40 -07:00
Ben Konyi a8aba7fab8 [ Service ] Add support for isolate-based RPCs to dart_runtime_service_vm
This change adds initial support for working with isolates in the Dart
Runtime Service and its backends.

The new `IsolateManager` base class tracks the set of active isolates
and their lifecycle events. The `VmIsolateManager` extends this class,
adding support specific to interacting with isolates within the Dart VM.

TEST=vm/cc/DartAPI_InvokeVMServiceMethod*_Exp

Change-Id: I3dfa298722c40dbdfdd58105cc78f31d058dd7a2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/486560
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
Reviewed-by: Jessy Yameogo <yjessy@google.com>
2026-03-12 09:08:14 -07:00
Ben Konyi f7a049dfb4 [ Service ] Initial implementation of VM Service based on package:dart_runtime_service
This change includes an initial implementation of the new VM service
implementation based on `package:dart_runtime_service`, along with the
necessary plumbing to start it in place of the legacy VM service
implementation.

The entrypoint for the new VM service implementation is located in
dart_runtime_service_vm/bin/vm_service_entrypoint.dart, which is
compiled into AppJIT and AOT snapshots when the
`--include-experimental-vm-service` flag is provided to `build.py`. To run
the VM with the new VM service implementation, the
`--experimental-vm-service` flag must be provided.

Currently, the experimental VM service implementation supports:

  - User specified ports
  - Authentication code flags
  - Enabling the HTTP server via SIGQUIT
  - Some service protocol RPCs that don't require an isolate ID (e.g.,
    `getVM`)

See go/dart-runtime-services-unification for more details.

TEST=Manual

CoreLibraryReviewExempt: dart:_vmservice is private
Change-Id: I4a58cd1fa0a386313baa3d5c5345720231279123
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/484820
Reviewed-by: Nicholas Shahan <nshahan@google.com>
Reviewed-by: Alexander Thomas <athom@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Ben Konyi <bkonyi@google.com>
2026-03-10 13:27:01 -07:00
Ryan Macnak 38743dd774 [vm] Remove unused dependency on ICU i18n.
TEST=ci
Change-Id: I6a09ef8af516495d479b5969aa89c9b2ceb9dc6f
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/486824
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2026-03-10 12:36:30 -07:00
Ryan Macnak a74e0132e8 [build] Generate DW_AT_variables for bin_to_assembly data outputs.
This lets bloaty attribute the data symbol to its source file, allowing the binary size visualization to nest it appropriately.

TEST=runtime/tools/binary_size
Change-Id: I683ad6729d2fe2e1730dd3be70c6cce15bdf0003
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/486524
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2026-03-10 09:14:30 -07:00
Ryan Macnak 5e173fa736 [vm] Mark natives as unreachable in gen_snapshot.
This allows a great deal of linker GC resulting in a much smaller binary. The benefit multiplies for Flutter development because the Flutter tool downloads many variant copies of gen_snapshot.

out/ReleaseX64/exe.stripped/gen_snapshot -1.55M (-23.4%)

TEST=ci
Change-Id: I9f6e650f78ea52c9c6953320a669b71019403236
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/482965
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2026-02-24 10:08:30 -08:00
Ryan Macnak 293e84cd5c [vm] Use /Zc:preprocessor to get __VA_OPT__ under MSVC.
Needed by irregexp.

TEST=ci
Change-Id: Ie64ee2869ddbb5bad234aea9b49d140b96fed2be
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/481242
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2026-02-18 09:18:10 -08:00
Arbaaz Ahmed e2c278d03b [vm] Allow to skip crash handler installation in bin::Platform::Initialize.
Closes https://github.com/dart-lang/sdk/pull/62680

GitOrigin-RevId: cfb5a10ad92bf8a2b0f56486b8b69b626b9bef44
Change-Id: I853d91c1f3a8b1184455489653510e562c17ebaf
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/480880
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2026-02-17 03:56:29 -08:00
Liam Appelbe 4679c040c6 [vm] Sync ffi callbacks can enter owned target isolate
Adds a new code path for NativeCallable.isolateLocal invocations. If
the current thread is not entered into any isolate, but owns the
target isolate, then it enters the target isolate, invokes, then exits
the isolate.

Fixes: https://github.com/dart-lang/sdk/issues/61623
TEST=tests/ffi/function_callbacks_isolate_ownership_test.dart
Change-Id: I401f185fadf7d2a55190dafd15387e1c418c67c9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/452380
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Liam Appelbe <liama@google.com>
2026-02-05 01:29:23 -08:00
Ryan Macnak 1dc4277e5b [vm] Remove dead code.
TEST=ci
Change-Id: Ic162deea4a39869a158726616e5c8dc0ff058817
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/475781
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2026-01-27 09:14:39 -08:00
Slava Egorov 25ffce7e36 [vm/win] Avoid unnecessary consoles for dartvm.exe
If dart.exe is not attached to the console then it should spawn
dartvm.exe detached to avoid creating an unnecessary console
window.

Fixes https://github.com/dart-lang/build/issues/4312

TEST=standalone/io/windows_no_unnecessary_console_test

Change-Id: I1de65accca5e28f3cfbe44a70f782525f0059bf0
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/475000
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Daco Harkes <dacoharkes@google.com>
2026-01-22 08:17:43 -08:00
Ryan Macnak cd5b99154f [vm] Fix potential upref of null in GenerateAppAOTAsAssembly.
Fixes GCC TSAN build.

TEST=local build
Change-Id: I8e7829835b412a9f5fdf638c793d6acf4a2dc501
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/472664
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2026-01-20 09:49:35 -08:00
Alexander Aprelev b4c47fd691 [ubsan] Fix parameter type mismatch ubsan for DestroyWatch callback.
Fixes https://github.com/dart-lang/sdk/issues/62365
TEST=ci

Change-Id: I70232a592c3382b1833eeffa499e713ef2cadbc2
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/471342
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2026-01-12 09:41:47 -08:00
Alexander Aprelev 61c3fbc220 [vm/build/ubsan/win] Fix ubsan build on Windows
- copy sanitizer runtime when using ubsan;
- avoid use of winnt.h CONTAINING_RECORD since it triggers ubsan "member access within null-pointer of type" error, use our copy which uses `offsetof`;
- have default virtual destructor in `ValueObject` to avoid ubsan complains about "insufficient space for an object of type 'dart:ValueObject'" at NoTemporaryAllocator use/declaration site;
- have virtual destructor in ZoneAllocated to avoid ubsan complains about "not having enough space to allocate object" at new RegExpEmpty() instantiation site;
- avoid using crashpad with ubsan as it causes dartvm to exit with error code 3;
- switch to windows, mac-friendly `[[gnu::no_sanitize(check)]]` from `__GNUC__` and `__has_feature` checks.

TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/62267
Change-Id: I8b922a8da329af276d4cefaa88fb841cc0457124
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/469840
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2026-01-07 12:38:27 -08:00
Ryan Macnak b18ec187d0 [build] Bump mac_sdk_min to 14.0.
TEST=ci
Change-Id: I92eb459a037ce8e4d1f98d1e28d7fd483f08f242
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/468883
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Brian Quinlan <bquinlan@google.com>
2026-01-05 13:06:49 -08:00
Daco Harkes b277407152 [ffi][cfe] Support @Native() external Array<Struct> fields
For structs, we were already loading the size of the struct at
runtime for the size of the memcopy. This CL makes that work for
the `Array`s as well.

TEST=pkg/vm/testcases/transformations/ffi/regress_62087.dart
TEST=tests/ffi/native_assets/asset_absolute_test.dart

Closes: https://github.com/dart-lang/sdk/issues/62087
Change-Id: I15a5796d713879a613971e080d18101111704b9b
Cq-Include-Trybots: dart/try:vm-aot-linux-debug-arm64-try,vm-aot-linux-debug-x64-try,vm-aot-linux-debug-x64c-try,vm-aot-mac-debug-arm64-try,vm-aot-mac-debug-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-x64-try,vm-aot-win-debug-x64c-try,vm-asan-linux-release-arm64-try,vm-asan-linux-release-x64-try,vm-asan-mac-release-arm64-try,vm-asan-win-release-x64-try,vm-dyn-linux-debug-x64-try,vm-dyn-mac-debug-arm64-try,vm-ffi-dyn-mac-debug-simarm64_arm64-try,vm-msan-linux-release-arm64-try,vm-msan-linux-release-x64-try,vm-tsan-linux-release-arm64-try,vm-tsan-linux-release-x64-try,vm-tsan-mac-release-arm64-try,vm-ubsan-linux-release-arm64-try,vm-ubsan-linux-release-x64-try,vm-ubsan-mac-release-arm64-try,vm-ubsan-win-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/464706
Reviewed-by: Tess Strickland <sstrickl@google.com>
Reviewed-by: Michael Goderbauer <goderbauer@google.com>
2026-01-05 08:01:26 -08:00
Slava Egorov 96eece84bd [vm/io] Avoid %ls in SetOsErrorMessage
This format specifier does not perform a wide char to utf8 conversion
but rather a locale dependent wide char to multibyte conversion 
(essentially wcstombs), which is not what this function is expecting
to do (it is expected to return utf8 encoded error message). 

Issue https://github.com/dart-lang/sdk/issues/62252

TEST=not tested, speculative fix

Change-Id: Icd5ddbf9969dbd4acd2f7f48626ce0bd6a6a6964
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/468800
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2025-12-17 03:20:11 -08:00
Ryan Macnak ee4ec6c84d [vm] Maintain W^X when mapping snapshots on Windows.
TEST=ci
Bug: https://github.com/dart-lang/sdk/issues/62249
Change-Id: I4ee4e7420527907d20217916acbc4162d9a53800
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/468441
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-12-16 09:22:52 -08:00
Ryan Macnak 583fbe5962 [vm] Symbolize more Windows errors.
TEST=build
Bug: https://github.com/dart-lang/sdk/issues/62249
Change-Id: I66e5cff2c965c1078ee59338bf5f0c4d061cec95
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/468400
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-12-15 15:45:21 -08:00
Alexander Aprelev 7cf7000a41 [vm/dartdev] Pass package_config option to spawned executable.
Fixes https://github.com/dart-lang/sdk/issues/62009
TEST=dartdev/run_test

Change-Id: I8fc114268d2f438fc78fa6b32f2d50e4b85cde91
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/464660
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
2025-12-01 11:28:58 -08:00
Slava Egorov 473149f0b1 [io] Fix Process::Exec stdio handle inheritance
The code for inheriting stdio handles was not taking into account that
some of the stdio handles might be the same causing them to be
duplicated in the list of inherited handles. However passing duplicate
handles in PROC_THREAD_ATTRIBUTE_HANDLE_LIST causes CreateProcess to
return E_INVALIDARG.

This CL fixes the code to avoid duplicate handles.

We also fix printing of errors, which was broken when Process::Exec
was used without Dart scope causing it to print (null) instead of
actual error message.

Fixes https://github.com/dart-lang/sdk/issues/61981

TEST=vm/dart/regress_61981

Fixed: 61981
Change-Id: I93a6b56476f5020de9ebf894614cee51586b6751
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/464382
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2025-11-25 11:59:21 -08:00
Daco Harkes ef30b3cc99 [vm/ffi] Test and Document NativeFinalizer Dart API limitations
Explicitly allow calling `Dart_DeletePersistentHandle` and
`Dart_DeleteWeakPersistentHandle` from `NativeFinalizers`.

And exercise this behavior in tests.

TEST=tests/ffi/vmspecific_native_finalizer_api_calls_test.dart
TEST=tests/ffi/vmspecific_native_finalizer_isolates_test.dart

Closes: https://github.com/dart-lang/sdk/issues/62076
CoreLibraryReviewExempt: VM-only. Doc-only.
Change-Id: I4915092e4b13cc55d0d48e7977149fb32059b854
Cq-Include-Trybots: luci.dart.try:vm-aot-linux-debug-x64-try,vm-dyn-linux-debug-x64-try,vm-linux-debug-x64-try,vm-ubsan-linux-release-x64-try,vm-tsan-linux-release-x64-try,vm-msan-linux-release-x64-try,vm-asan-linux-release-x64-try,vm-ffi-mac-debug-simarm64_arm64-try,vm-win-debug-x64-try,vm-reload-linux-debug-x64-try,vm-gcc-linux-x64-try,vm-appjit-linux-debug-x64-try,vm-aot-linux-release-x64-try,vm-aot-dyn-linux-debug-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/464180
Commit-Queue: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Liam Appelbe <liama@google.com>
2025-11-25 02:50:47 -08:00
Ryan Macnak 015e6b0873 [standalone] Uses of dlopen should be guarded by host OS.
TEST=cross-build
Bug: https://github.com/dart-lang/sdk/issues/62081
Change-Id: I39b54f121920dac7d2f2eda54d8cb29edbdccc30
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/464243
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2025-11-24 12:38:30 -08:00
Alexander Markov d8f9455cd1 Fix Windows cross-build targeting Linux
TEST=ci
Fixes https://github.com/dart-lang/sdk/issues/62056

Change-Id: Ic5bcee5bd1f3499e4337d573c2adec6c30131a8a
Cq-Include-Trybots: luci.dart.try:pkg-win-release-try,pkg-win-release-arm64-try,vm-aot-mac-debug-arm64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/463720
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-11-21 11:03:32 -08:00
Alexander Markov a37d042e68 [vm] Initial implementation of module snapshot reader
TEST=manual
Issue: https://github.com/dart-lang/sdk/issues/61635

Change-Id: I27f712d9687d45a09173b1018bc08812dd18658e
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/460580
Reviewed-by: Slava Egorov <vegorov@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-11-21 06:42:16 -08:00
Tess Strickland a58a41c27e [vm] Use Snapshot::TryReadAppSnapshot in analyze_snapshot.
This allows analyze_snapshot to analyze Mach-O snapshots as well, and
also removes the restriction on only building analyze_snapshot for
Linux and Android.

TEST=vm/dart/analyze_snapshot_binary_test

Change-Id: I82797db2f20a4a80cdc52922aeebc789f45bf9bb
Cq-Include-Trybots: luci.dart.try:vm-aot-mac-release-arm64-try,vm-aot-win-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/461482
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2025-11-19 07:54:19 -08:00
Tess Strickland bc021bbc01 [vm] Output accompaning relocatable object for Mach-O snapshots.
In order to appropriately generate .dSYMs for a snapshot and allow
the strip tool to be used on the snapshot afterwards, add a mode that
not only outputs the snapshot (sans DWARF information) but also
an associated relocatable object file that contains the program's DWARF
information. That allows dsymutil to retrieve the DWARF information
from the relocatable object when run on the snapshot prior to stripping.

To specify that the relocatable object file should be output, use
the new --macho-object command line argument to gen_snapshot
to specify where the object file should be written.

This CL also adds an additional command line argument,
--macho-reduce-padding, which reduces the alignment used for segments
and the text/const sections in Mach-O outputs from 16KB to 64 bytes.
The larger padding is needed for some uses, like non-native loading
of Mach-O objects, but can be elided for other uses like Flutter builds.

TEST=vm/dart/use_dwarf_stack_traces_flag_test
     vm/dart/use_macho_reduce_padding_flag_test

Change-Id: I2bf4bacb70c41299b8b6fdb7635c2374acf7a07d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/457420
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Tess Strickland <sstrickl@google.com>
2025-11-19 07:45:52 -08:00
Alexander Aprelev de77c6b766 [vm/shared] Introduce ScopedThreadLocal to allow keeping state on
thread, outside of isolate, on isolate-group bound callback.

Fixes https://github.com/dart-lang/sdk/issues/61523
TEST=scoped_thread_local_test

Change-Id: I0c8280d2808d940a5fb0d628db191932400a5edb
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/451402
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2025-11-13 09:50:34 -08:00
Ryan Macnak 17a37d2fa6 [test] Avoid data race checking for isolate cleanup callback.
Remove manual MSAN unpoisoning that should happen automatically for Pointer/TypedData writes.

TEST=tsan, msan
Bug: https://github.com/dart-lang/sdk/issues/61503
Bug: https://github.com/dart-lang/sdk/issues/61772
Change-Id: I7c3af7ad769f36a869de7f4d8125d0ced47c9ec7
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/458069
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-10-29 08:28:41 -07:00
Slava Egorov 5d959c757f [io] Fix Flutter Android build
It seems that socklet_t is sometimes defined as a signed type which
causes a signed vs unsigned comparison warning and breaks the build as a
result.

TEST=manual build

Change-Id: Ie30c1b0615fc93b6589a0894b48ce7006a6a6964
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/458280
Auto-Submit: Slava Egorov <vegorov@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Martin Kustermann <kustermann@google.com>
2025-10-29 07:25:33 -07:00
Slava Egorov e50d3b98a3 [io] Support Unix domain sockets on Windows
Basic support for Unix domain sockets on Windows within
the limitations of the operating system itself: no 
support for abstract addresses, datagram or 
packet sockets and ancillary data.

This also fixes File::GetType on Windows to correctly
identify reparse points representing AF_UNIX sockets
as such, rather then identify them as links.

Finally, it is worth noting that there is an existing
discrepancy between POSIX OSes and Windows: on POSIX OSes
File(sockPath).existsSync() returns true, but on Windows the 
same code returns false because Unix domain sockets are not 
considered regular files by stat. 

This CL does a bunch of refactoring around RawAddr class which
surves as a wrapper around various structures in sockaddr_* family.
Distinguishing anonymous AF_UNIX address from abstract AF_UNIX
address requires passing around the length of the address
structure. Thus we incorporate this information into
RawAddr. This will also make possible to properly support
full-range of abstract AF_UNIX addresses in the future because
supporting these requires properly handling embedded NUL bytes.
(See https://github.com/dart-lang/sdk/issues/46158).

Fixes https://github.com/dart-lang/sdk/issues/41161

TEST=standalone/io/unix_socket

Cq-Include-Trybots: luci.dart.try:vm-fuchsia-release-x64-try
Change-Id: I016cb33ebdd62f0cac1ae97d822105366a6a6964
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/457720
Reviewed-by: Martin Kustermann <kustermann@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2025-10-29 05:25:24 -07:00
Slava Egorov dec87b98f0 [io] Provide dart::bin::SetupDartIoLibrary
Instead of requiring embedder to initialize dart:io by bits and pieces
by invoking various hooks and setting fields provide a structured C++
API for preparing dart:io for execution.

TEST=ci

CoreLibraryReviewExempt: VM specific changes only
Change-Id: I66e95c0a451d384b4f7582d1df059e506a6a6964
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/454062
Reviewed-by: Ryan Macnak <rmacnak@google.com>
Commit-Queue: Slava Egorov <vegorov@google.com>
2025-10-14 13:15:21 -07:00
Slava Egorov 07c9599ead [vm] Tweak location of Perfetto protos
This CL tries to address version skew issues which occur in internal
monorepo which we created by checking in *.pbzero.h files into
runtime/vm/protos/*. These files refer to protozero internal headers,
which in the internal monorepo come from a shared Perfetto dependency
which does not necessarily match the version we pinned in our DEPS and
used to generated these files.

This version skew caused problems for the Perfetto team, see
https://github.com/google/perfetto/pull/3195

To resolve this change layout of our repo to allow us to depend on the
shared Perfetto entirely - including its version of *.pbzero.h headers.

We change include paths in the VM source to

    #include "third_party/perfetto/protos/..."

which match location of these headers in the internal monorepo.

To make the code compile in the normal SDK checkout we shift location of
Perfetto and checked in code:

* Perfetto source moves from third_party/perfetto to
  third_party/perfetto/src.
* Generated code moves from runtime/vm/protos into
  third_party/perfetto/protos.

Note: experiments show that *.pbzero.h files tree-shake very well and
you pay only for things that you use. That means depending on *.pbzero.h
files generated from full message definitions rather than our manually
tree-shaken versions does not actually increase the size of the VM
binaries. We could switch our external build to do the same but this
would make protoc a build time dependency, which seems excessive.

TEST=ci

Change-Id: I724b9d9304be83302a5d83c2337154b36a6a6964
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/454260
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Ben Konyi <bkonyi@google.com>
2025-10-13 02:09:31 -07:00
Ryan Macnak 9bcd33c50b Reapply "[standalone] Use fewer syscalls to get entropy on Linux and Mac."
Use SecRandomCopyBytes on Mac/iOS.

TEST=ci, local engine build
Change-Id: I48e1fc0186e4a65419fd9bf02be4d91983f8d8d9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/453581
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2025-10-08 08:16:42 -07:00
Slava Egorov c70a4b08a2 [io] Fix Mac OS X file watcher
Fixes bug in commit 25df2b3f11.

The code for converting FSEventStream notification into Dart format 
was checking file existence using relative path instead of absolute
path. This caused it to incorrectly classify rename events which
were creations as deletions.

This was not caught by testing because this was not well covered
by the test and the test closest to checking this was even 
disabled on Mac. CL updates updates the test to cover this better. 

Fixes https://github.com/dart-lang/sdk/issues/61693

TEST=standalone/io/file_system_watcher_test

Change-Id: I2a7c984dfcec0be74c974f13b6ead7d86a6a6964
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/453880
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2025-10-08 02:25:17 -07:00
Alexander Markov e48ff95649 Revert "[standalone] Use fewer syscalls to get entropy on Linux and Mac."
This reverts commit ea162825d3.

Revert "[standalone] Fix Linux Crypto::GetRandomBytes on MSAN."

This reverts commit c3e5b7c268.

Reason for revert: build failures on "Mac mac_ios_engine" Flutter bot:
```
../../../flutter/third_party/dart/runtime/bin/crypto_macos.cc:10:10: fatal error: 'sys/random.h' file not found
   10 | #include <sys/random.h>
      |          ^~~~~~~~~~~~~~
1 error generated.
```

https://ci.chromium.org/ui/p/flutter/builders/try/Mac%20mac_ios_engine/50544/overview

TEST=ci

Change-Id: Ib0656cbf1268fc48f42097b09ca60c5bf2c1e2bd
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/452843
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Markov <alexmarkov@google.com>
2025-10-02 07:37:07 -07:00
Ryan Macnak c3e5b7c268 [standalone] Fix Linux Crypto::GetRandomBytes on MSAN.
TEST=msan
Change-Id: Ifcf3c2939363eade8fb9e2e169b74a6d102c74a6
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/452908
Reviewed-by: Alexander Aprelev <aam@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
2025-10-01 15:28:50 -07:00
Alexander Aprelev ad318128f5 [io] Fix race between closing socket and requesting its type.
Fixes https://github.com/dart-lang/sdk/issues/61582

Revert "[io/socket] Make Socket::fd_ atomic since it can get updated from multiple threads."
Revert "[gardening] Fix fuchsia build - assign atomic to intptr_t before reinterpret_cast to pointer."

TEST=ci

Change-Id: Ia755d6623e46b7940800a12bf4a5d8d9cb674522
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/451822
Reviewed-by: Slava Egorov <vegorov@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2025-10-01 15:15:20 -07:00
Ryan Macnak ea162825d3 [standalone] Use fewer syscalls to get entropy on Linux and Mac.
TEST=ci
Change-Id: Ib4737145a34b1d5e4aeab4377f918745abe8e1fa
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/452220
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2025-10-01 13:01:38 -07:00
Slava Egorov 25df2b3f11 [io] Rewrite Mac OS X FS watcher
Watcher used pipes to fit into the "socket"-like implementation used by
other OSes. However it turns out that pipe buffer on Mac OS X is not
necessarily large enough to fit the whole FSEvent structure meaning that
we can't expect to be able to read FSEvents atomically from a pipe.

This situation happens because Mac OS X inherits BSD behavior of
limiting total number of kernel memory reserved for pipe buffers. Once
kern.ipc.maxpipekva limit is crossed pipe buffers no longer grow to 64KB
and remain 512 bytes large (which is absolute minimum allowed by POSIX
which requires writes smaller than PIPE_BUF to be atomic).

So our code needs to be prepared that only half of FSEvent structure
(which is 1032 bytes large) will fit into pipe buffer.

We could fix this by reading each FSEvent in chunks but this seems
ridiculously ineffecient. Instead we rewrite the code to pass file
system events via SendPort instead.

Fixes https://github.com/dart-lang/sdk/issues/61551

TEST=runtime/tests/vm/dart/regress_61551_test.dart

CoreLibraryReviewExempt: VM only changes.
Change-Id: I6a6a696499044832cfb61998bc6a519bbaadf8bc
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/451260
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2025-10-01 11:28:05 -07:00
Slava Egorov ed6bab847b [io] Rewrite _FileSystemWatcher implementation
Existing implementation is an entangled mess which consists of shared
code residing in the base class which in random places invokes a number
of undocumented poorly named methods overloaded in OS specific
subclasses. Some of these methods mutate static state. There are no
clear lifetime guarantees for different parts of the system (including
comments saying that some values might or might not be valid at certain
points).

The rewrite aims to clean most of this up - sharing everything that can
be shared and moving OS specific logic to clearly documented methods.

Furthermore, we change the code to ensure proper lifetime guarantees -
so we no longer find ourself in situations where we don't know whether
pathId is valid or not.

This refactoring by itself fixes a number of issues, most specifically a
bug where watcher would stop receiving events on Windows because
DirectoryWatchHandle ends up allocated at precisely the same address as
a previous destroyed one - which confuses Dart side to think that newly
created handle is the same as the old one (due to a race between event
handler thread and Dart thread).

We fix Windows lifetime issue by a) not keeping pathId based mapping in
the watcher anymore and b) keeping DirectoryWatchHandler alive until it
is stoped by the Dart side - this is achieved by retaining it after it
is created and releasing it once path is unwatched. This way Dart side
is always sure that pathId values are valid until they are explicitly
released via _unwatchPath - which makes code very uniform.

To make sure that native objects created by _watchPath are released when
surrounding isolate exists abruptly (e.g. via Isolate.exit - without
letting Dart code to shutdown and call _unwatchPath naturally) we attach
NativeFinalizer to them. This fixes the existing leak of file watchers
on Mac OS X - as Node objects it created were not freed if surrounding
isolate exited. Note that inotify descriptors did not leak in the same
way because they were wrapped into sockets.

Finally, this refactoring also make sure that the last subscriber
cancelling subscription on filesystem event stream will get a proper
cancellation future back and can wait for the watcher to shutdown.
Previously implementation used broadcast streams which simply return an
already completed future when subscriber cancels. New implementation
uses Stream.multi instead which gives a better result. Now doing
watch().listen().cancel() returns a future which will only complete once
watcher is fully disposed (e.g. inotify descriptor is closed). Bad
behavior was revealed by analysing standalone/regress_52715 - which
revealed that repeatedly watching and cancelling might flakely cause us
to hit fd limit depending on whether eventhandler thread can keep up
closing file descriptors created by the main thread or not.

Fixes https://github.com/dart-lang/sdk/issues/61378

TEST=standalone/{regress_61378,file_system_watcher_isolate_exit_leak}

CoreLibraryReviewExempt: VM only changes.
Change-Id: I6a6a69642b1f2673f2be78434bc64270846ad8c5
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/450921
Reviewed-by: Lasse Nielsen <lrn@google.com>
2025-10-01 11:28:05 -07:00
Slava Egorov f434804f6b [io] Simplify Mac OS X FileSystemWatcher
Use a single dispach queue instead of manually managed threads with run
loops.

TEST=ci

Change-Id: I6a6a696489ebd41305027b5cef7fccb73b1f6731
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/452140
Reviewed-by: Alexander Aprelev <aam@google.com>
2025-10-01 11:28:05 -07:00
Slava Egorov 3dfad7dd69 [vm] Remove traces of dart:concurrent from Builtin.
This library no longer has old school natives and uses FFI natives
instead which are configured in bootstrap instead.

TEST=ci

Change-Id: I6a6a6964e1ee692153dfeb8dbaf692b35851e893
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/452141
Reviewed-by: Alexander Aprelev <aam@google.com>
2025-10-01 11:28:05 -07:00
Ryan Macnak f1ba8ceacf [vm] Make some IgnoreRace functions inlinable.
Fix GCC TSAN build.
Cleanup sanitizer includes.

TEST=ci
Change-Id: Ib68bbfa701b4309c03514ed689391051094208e4
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/452226
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
2025-10-01 09:41:26 -07:00
Alexander Aprelev dee968bcd8 [gardening] Fix fuchsia build - assign atomic to intptr_t before reinterpret_cast to pointer.
Follow-up to https://dart.googlesource.com/sdk/+/a5b0fc041990624b8c8a9a9c846bdba98d3b07d7.

TEST=ci

Bug: https://ci.chromium.org/ui/p/dart/builders/ci.sandbox/vm-fuchsia-release-x64/11814/overview
Change-Id: I08abe6fb4ca26475fa689ad817add38fa27b9f24
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/451551
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Tess Strickland <sstrickl@google.com>
2025-09-26 08:38:53 -07:00
Alexander Aprelev a5b0fc0419 [io/socket] Make Socket::fd_ atomic since it can get updated from multiple threads.
Follow-up to https://dart.googlesource.com/sdk/+/ba7aaa929f579aaa55a2fc09a098f81df6b27804, sink the "is fd closed" check to avoid multiple reads.

Fixes https://github.com/dart-lang/sdk/issues/61582
TEST=ci

Change-Id: Id00cd8ad8b7831006ad47c665ac09eb9f38fa6f9
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/451600
Reviewed-by: Tess Strickland <sstrickl@google.com>
Commit-Queue: Alexander Aprelev <aam@google.com>
2025-09-26 07:01:23 -07:00
Alexander Aprelev ba7aaa929f [io/win] Ensure to check if socket is still open when requesting its type.
Fixes https://github.com/dart-lang/sdk/issues/61571
TEST=stdin_cancel_type_test

Change-Id: I5e0a1837e72a6e41a53fc7fe163b8931082e7405
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/451381
Commit-Queue: Alexander Aprelev <aam@google.com>
Reviewed-by: Ryan Macnak <rmacnak@google.com>
2025-09-24 21:10:40 -07:00
Artem Strygin 1dc1d36820 [vm] Add C Api for maps making.
Also allow to write simple conversions from std::map to "Dart Map" using
"c++ template magic".

R=alexmarkov@google.com

TEST=vm/cc/DartAPI_MapCreate

Bug: nothing
Change-Id: I11f3271df6880825bd417ee5532c56bacfa7278d
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/449280
Auto-Submit: Art Snake <art-snake@yandex-team.ru>
Commit-Queue: Slava Egorov <vegorov@google.com>
Reviewed-by: Alexander Markov <alexmarkov@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
2025-09-18 06:56:21 -07:00
Artem Strygin 522e611c9d [vm] Add useful type getters to C API
This allows direct access to String, int, bool, double, Object types
instead of requiring name based lookups via Dart_LookupLibrary and
Dart_GetType.

R=dacoharkes@google.com

TEST=vm/cc/DartAPI_CoreTypes

Change-Id: I2aba317be3b4be21f37d61843a328a5146417e54
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/450160
Reviewed-by: Daco Harkes <dacoharkes@google.com>
Reviewed-by: Slava Egorov <vegorov@google.com>
Auto-Submit: Art Snake <art-snake@yandex-team.ru>
Commit-Queue: Slava Egorov <vegorov@google.com>
2025-09-18 04:45:29 -07:00