[L] Change in dart/sdk[main]: [ffi] Reland: Add DynamicLibrary.openFromAssetId

0 views
Skip to first unread message

Shikhar Soni (Gerrit)

unread,
Jun 16, 2026, 8:13:28 AM (10 days ago) Jun 16
to dart-...@luci-project-accounts.iam.gserviceaccount.com, Daco Harkes, Slava Egorov, dart-dc-te...@google.com, rev...@dartlang.org, vm-...@dartlang.org
Attention needed from Daco Harkes and Slava Egorov

Shikhar Soni added 4 comments

Commit Message
Line 14, Patchset 2:This CL fixes that bug and relands the changes.
Daco Harkes . resolved

What was the bug? And what was the diff?

Shikhar Soni

There was a logic error in case an embedder(like flutter engine) provided a `dlopen` hook but didn't find the asset.

Diff:
```
if (native_assets_api->dlopen != nullptr) {
NoActiveIsolateScope no_active_isolate_scope;
handle = native_assets_api->dlopen(asset.ToCString(), error);
- *asset_found = *error == nullptr;
- return handle;
+ if (*error != nullptr || handle != nullptr) {
+ *asset_found = true;
+ return handle;
+ }
}
```

I don't know what the procedure is in cases like this: submitting a patch only for the bug or a complete new patch for this.

Daco Harkes

Usually we put the reland in the first patch set and then we put the fix in patchset 2.

And the CL is usually titled: Reland: ...

Shikhar Soni

Acknowledged

File runtime/bin/native_assets_api_impl.cc
Line 150, Patchset 2:void* NativeAssets::DlopenProcess(char** /*error*/) {
Daco Harkes . resolved

unrelated change?

Shikhar Soni

Acknowledged

File runtime/lib/ffi_dynamic_library.cc
Line 357, Patchset 2: *asset_found = true;
Daco Harkes . resolved

I don't think this behavior is correct. `dlsym(nullptr, ...)` on linux does process lookup and can be used by the embedder. So, we cannot get the correct behavior with the current embedder API.

The flutter embedder uses:

```
void* NativeAssets::DlopenProcess(char** /*error*/) {
#if defined(DART_HOST_OS_LINUX) || defined(DART_HOST_OS_MACOS) || \
defined(DART_HOST_OS_ANDROID) || defined(DART_HOST_OS_FUCHSIA)
return RTLD_DEFAULT;
#else
return kWindowsDynamicLibraryProcessPtr;
#endif
}
```

from engine/src/flutter/runtime/dart_isolate.cc

for `native_assets_api->dlopen`.

So here we have the same issue as we saw before in the Dart standalone VM we cannot distinguish between lookup succeeding and returning `RTLD_DEFAULT` and the asset missing.

I think we need to introduce an `native_assets_api->dlopen_v2` that takes an extra `asset_found` param. (Adding a `native_assets_api->has_asset` would be simpler, but slower.)

Then if `native_assets_api->dlopen_v2` is not nullptr, we use that. Then if `native_assets_api->dlopen` is not nullptr we use that and are on the safe-side with asset-found like in your change here. And otherwise we fall back to the ffi:native-assets library.

(Using `native_assets_api->dlopen` for `DynamicLibrary.fromAssetId` will give the wrong behavior. So, it would be even better if the code-path for that would give an `error` saying that the operation is not supported. And then when we move Flutter to _v2 Flutter will start supporting the new API.)

Shikhar Soni

Acknowledged

Line 361, Patchset 2: if (*error == nullptr && handle == nullptr) {
Daco Harkes . resolved

This is always true due to early return.

Shikhar Soni

Acknowledged

Open in Gerrit

Related details

Attention is currently required from:
  • Daco Harkes
  • Slava Egorov
Submit Requirements:
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement satisfiedCommit-Message-Has-TEST
  • requirement satisfiedCore-Library-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: If9b37249cffd2a454644f11259c089f95f4d1d69
Gerrit-Change-Number: 511960
Gerrit-PatchSet: 5
Gerrit-Owner: Shikhar Soni <shikh...@google.com>
Gerrit-Reviewer: Daco Harkes <dacoh...@google.com>
Gerrit-Reviewer: Slava Egorov <veg...@google.com>
Gerrit-Attention: Slava Egorov <veg...@google.com>
Gerrit-Attention: Daco Harkes <dacoh...@google.com>
Gerrit-Comment-Date: Tue, 16 Jun 2026 12:13:23 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Daco Harkes <dacoh...@google.com>
Comment-In-Reply-To: Shikhar Soni <shikh...@google.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Shikhar Soni (Gerrit)

unread,
Jun 16, 2026, 8:16:28 AM (10 days ago) Jun 16
to dart-...@luci-project-accounts.iam.gserviceaccount.com, Daco Harkes, Slava Egorov, dart-dc-te...@google.com, rev...@dartlang.org, vm-...@dartlang.org
Attention needed from Daco Harkes and Slava Egorov

Shikhar Soni added 1 comment

Patchset-level comments
File-level comment, Patchset 5 (Latest):
Shikhar Soni . unresolved
  • added `NativeAssetsApi::dlopen_v2`
  • `dlopen_v2` reports `asset_found`
  • it also report `can_be_closed`, because `DynamicLibrary.openFromAssetId` must preserve close semantics
  • legacy `dlopen` remains only for `@Native` compatibility
Gerrit-Comment-Date: Tue, 16 Jun 2026 12:16:18 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
unsatisfied_requirement
satisfied_requirement
open
diffy

Daco Harkes (Gerrit)

unread,
Jun 22, 2026, 3:24:31 AM (4 days ago) Jun 22
to Shikhar Soni, dart-...@luci-project-accounts.iam.gserviceaccount.com, Slava Egorov, dart-dc-te...@google.com, rev...@dartlang.org, vm-...@dartlang.org
Attention needed from Shikhar Soni and Slava Egorov

Daco Harkes voted and added 6 comments

Votes added by Daco Harkes

Commit-Queue+1

6 comments

File runtime/lib/ffi_dynamic_library.cc
Line 443, Patchset 5 (Latest): } else if (allow_legacy_embedder_dlopen &&
Daco Harkes . unresolved

If only the legacy embedder dlopen is available and you try to do dlopenFromAssetId, the asset will not be found (via LoadAssetLibraryFromKernelMapping) that will probably lead to confusion for the end user.

I think it's better we do:

```
if (native_assets_api->dlopen != nullptr) {
  if (!allow_legacy_embedder_dlopen) {
*error = // ....
return result;
}
```
Line 495, Patchset 5 (Latest): Exceptions::ThrowUnsupportedError(
Daco Harkes . unresolved

I'd probably read the `error` value here and set it inside the helper function.

(We'll still need the if to branch correctly to a unsupported error instead of argument error 👍)

Line 499, Patchset 5 (Latest): const String& msg = String::Handle(String::NewFormatted(
Daco Harkes . unresolved

Use `native_assets_api->available_assets` if available for the error message so that we print which assets are available. (In case someone does a typo in the asset id.)

File sdk/lib/ffi/dynamic_library.dart
Line 35, Patchset 5 (Latest): /// Loads a library registered under the given [assetId] in the native assets
Daco Harkes . unresolved

Loads a code asset registered with [assetId] in a build hook.

Line 38, Patchset 5 (Latest): /// The [assetId] must be registered in the active native assets mapping.
Daco Harkes . unresolved

"native assets mapping" is not public API terminology.

Instead maybe refer to https://dart.dev/tools/hooks.

File tests/ffi/native_assets/asset_relative_test.dart
Line 149, Patchset 5 (Latest): testOpenFfiTestFunctionsAssetCanClose(assetId);
Daco Harkes . unresolved

also the system dylibs test.

Open in Gerrit

Related details

Attention is currently required from:
  • Shikhar Soni
  • Slava Egorov
Submit Requirements:
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement satisfiedCommit-Message-Has-TEST
  • requirement satisfiedCore-Library-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: If9b37249cffd2a454644f11259c089f95f4d1d69
Gerrit-Change-Number: 511960
Gerrit-PatchSet: 5
Gerrit-Owner: Shikhar Soni <shikh...@google.com>
Gerrit-Reviewer: Daco Harkes <dacoh...@google.com>
Gerrit-Reviewer: Slava Egorov <veg...@google.com>
Gerrit-Attention: Slava Egorov <veg...@google.com>
Gerrit-Attention: Shikhar Soni <shikh...@google.com>
Gerrit-Comment-Date: Mon, 22 Jun 2026 07:24:23 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
unsatisfied_requirement
satisfied_requirement
open
diffy

Daco Harkes (Gerrit)

unread,
Jun 22, 2026, 3:30:13 AM (4 days ago) Jun 22
to Shikhar Soni, dart-...@luci-project-accounts.iam.gserviceaccount.com, Slava Egorov, dart-dc-te...@google.com, rev...@dartlang.org, vm-...@dartlang.org
Attention needed from Shikhar Soni and Slava Egorov

Daco Harkes added 2 comments

Commit Message
Line 21, Patchset 5 (Latest):R=dacoh...@google.com, veg...@google.com
Daco Harkes . unresolved

And possibly this line too.

Line 22, Patchset 5 (Latest):
Daco Harkes . unresolved

This whitespace prevents the Cq try bots from triggering properly. (only one of the 3 dyn bots seems to be running)

Gerrit-Comment-Date: Mon, 22 Jun 2026 07:30:05 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
unsatisfied_requirement
satisfied_requirement
open
diffy

Shikhar Soni (Gerrit)

unread,
Jun 23, 2026, 3:15:03 AM (3 days ago) Jun 23
to Daco Harkes, dart-...@luci-project-accounts.iam.gserviceaccount.com, Slava Egorov, dart-dc-te...@google.com, rev...@dartlang.org, vm-...@dartlang.org
Attention needed from Daco Harkes and Slava Egorov

Shikhar Soni added 9 comments

Patchset-level comments
File-level comment, Patchset 2:
Daco Harkes . unresolved

I just realized that not knowing if the asset was found is also an issue for the dlopen call from the embedder API.

So we'll need to add a dlopen_v2 in the embedder API (to prevent manual rolls) that also has an asset-found out param.

You'll need to make a Flutter engine PR as well to migrate the Flutter engine.
https://github.com/flutter/flutter/blob/master/CONTRIBUTING.md
https://github.com/flutter/flutter/blob/master/docs/engine/contributing/Setting-up-the-Engine-development-environment.md
engine/src/flutter/runtime/dart_isolate.cc -> InitDartFFIForIsolateGroup

Shikhar Soni

Working on the flutter engine part.

Commit Message

And possibly this line too.

Shikhar Soni

Done

Line 22, Patchset 5:
Daco Harkes . resolved

This whitespace prevents the Cq try bots from triggering properly. (only one of the 3 dyn bots seems to be running)

Shikhar Soni

Done

File runtime/lib/ffi_dynamic_library.cc
Line 443, Patchset 5: } else if (allow_legacy_embedder_dlopen &&
Daco Harkes . resolved

If only the legacy embedder dlopen is available and you try to do dlopenFromAssetId, the asset will not be found (via LoadAssetLibraryFromKernelMapping) that will probably lead to confusion for the end user.

I think it's better we do:

```
if (native_assets_api->dlopen != nullptr) {
if (!allow_legacy_embedder_dlopen) {
*error = // ....
return result;
}
```
Shikhar Soni

Done

Line 495, Patchset 5: Exceptions::ThrowUnsupportedError(
Daco Harkes . unresolved

I'd probably read the `error` value here and set it inside the helper function.

(We'll still need the if to branch correctly to a unsupported error instead of argument error 👍)

Shikhar Soni

PTAL

Line 499, Patchset 5: const String& msg = String::Handle(String::NewFormatted(
Daco Harkes . unresolved

Use `native_assets_api->available_assets` if available for the error message so that we print which assets are available. (In case someone does a typo in the asset id.)

Shikhar Soni

PTAL

File sdk/lib/ffi/dynamic_library.dart
Line 35, Patchset 5: /// Loads a library registered under the given [assetId] in the native assets
Daco Harkes . resolved

Loads a code asset registered with [assetId] in a build hook.

Shikhar Soni

Done

Line 38, Patchset 5: /// The [assetId] must be registered in the active native assets mapping.
Daco Harkes . resolved

"native assets mapping" is not public API terminology.

Instead maybe refer to https://dart.dev/tools/hooks.

Shikhar Soni

Done

File tests/ffi/native_assets/asset_relative_test.dart
Line 149, Patchset 5: testOpenFfiTestFunctionsAssetCanClose(assetId);
Daco Harkes . resolved

also the system dylibs test.

Shikhar Soni

Done

Open in Gerrit

Related details

Attention is currently required from:
  • Daco Harkes
  • Slava Egorov
Submit Requirements:
  • requirement is not satisfiedCode-Owners
  • requirement is not satisfiedCode-Review
  • requirement satisfiedCommit-Message-Has-TEST
  • requirement satisfiedCore-Library-Review
  • requirement is not satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: If9b37249cffd2a454644f11259c089f95f4d1d69
Gerrit-Change-Number: 511960
Gerrit-PatchSet: 8
Gerrit-Owner: Shikhar Soni <shikh...@google.com>
Gerrit-Reviewer: Daco Harkes <dacoh...@google.com>
Gerrit-Reviewer: Slava Egorov <veg...@google.com>
Gerrit-Attention: Slava Egorov <veg...@google.com>
Gerrit-Attention: Daco Harkes <dacoh...@google.com>
Gerrit-Comment-Date: Tue, 23 Jun 2026 07:14:56 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Daco Harkes <dacoh...@google.com>
unsatisfied_requirement
satisfied_requirement
open
diffy

Daco Harkes (Gerrit)

unread,
Jun 23, 2026, 6:37:58 AM (3 days ago) Jun 23
to Shikhar Soni, dart-...@luci-project-accounts.iam.gserviceaccount.com, Slava Egorov, dart-dc-te...@google.com, rev...@dartlang.org, vm-...@dartlang.org
Attention needed from Shikhar Soni and Slava Egorov

Daco Harkes voted and added 1 comment

Votes added by Daco Harkes

Code-Review+1
Commit-Queue+1

1 comment

File runtime/lib/ffi_dynamic_library.cc
Line 495, Patchset 8 (Latest): native_assets_api->dlopen != nullptr;
Daco Harkes . unresolved

The second condition is not needed right?

Open in Gerrit

Related details

Attention is currently required from:
  • Shikhar Soni
  • Slava Egorov
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement satisfiedCode-Review
  • requirement satisfiedCommit-Message-Has-TEST
  • requirement satisfiedCore-Library-Review
  • requirement satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: If9b37249cffd2a454644f11259c089f95f4d1d69
Gerrit-Change-Number: 511960
Gerrit-PatchSet: 8
Gerrit-Owner: Shikhar Soni <shikh...@google.com>
Gerrit-Reviewer: Daco Harkes <dacoh...@google.com>
Gerrit-Reviewer: Slava Egorov <veg...@google.com>
Gerrit-Attention: Slava Egorov <veg...@google.com>
Gerrit-Attention: Shikhar Soni <shikh...@google.com>
Gerrit-Comment-Date: Tue, 23 Jun 2026 10:37:51 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
satisfied_requirement
open
diffy

Shikhar (Gerrit)

unread,
Jun 23, 2026, 7:15:52 AM (3 days ago) Jun 23
to Shikhar Soni, Daco Harkes, dart-...@luci-project-accounts.iam.gserviceaccount.com, Slava Egorov, dart-dc-te...@google.com, rev...@dartlang.org, vm-...@dartlang.org
Attention needed from Shikhar Soni and Slava Egorov

Shikhar added 1 comment

File runtime/lib/ffi_dynamic_library.cc
Line 495, Patchset 8 (Latest): native_assets_api->dlopen != nullptr;
Daco Harkes . unresolved

The second condition is not needed right?

Shikhar

It is, because `LoadAssetLibraryFromKernelMapping` can also return errors, so distinguish errors from that path and `UnsupportedError`...


I think I should return an `unsupported` flag from `LoadAssetLibrary`, that would be more clean.

Open in Gerrit

Related details

Attention is currently required from:
  • Shikhar Soni
  • Slava Egorov
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement satisfiedCode-Review
  • requirement satisfiedCommit-Message-Has-TEST
  • requirement satisfiedCore-Library-Review
  • requirement satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: If9b37249cffd2a454644f11259c089f95f4d1d69
Gerrit-Change-Number: 511960
Gerrit-PatchSet: 8
Gerrit-Owner: Shikhar Soni <shikh...@google.com>
Gerrit-Reviewer: Daco Harkes <dacoh...@google.com>
Gerrit-Reviewer: Slava Egorov <veg...@google.com>
Gerrit-CC: Shikhar <shikha...@gmail.com>
Gerrit-Comment-Date: Tue, 23 Jun 2026 11:15:45 +0000
satisfied_requirement
open
diffy

Daco Harkes (Gerrit)

unread,
Jun 23, 2026, 11:09:19 AM (3 days ago) Jun 23
to Shikhar Soni, Shikhar, dart-...@luci-project-accounts.iam.gserviceaccount.com, Slava Egorov, dart-dc-te...@google.com, rev...@dartlang.org, vm-...@dartlang.org
Attention needed from Shikhar, Shikhar Soni and Slava Egorov

Daco Harkes voted and added 4 comments

Votes added by Daco Harkes

Code-Review+1
Commit-Queue+1

4 comments

Patchset-level comments
File-level comment, Patchset 5:
Shikhar Soni . resolved
  • added `NativeAssetsApi::dlopen_v2`
  • `dlopen_v2` reports `asset_found`
  • it also report `can_be_closed`, because `DynamicLibrary.openFromAssetId` must preserve close semantics
  • legacy `dlopen` remains only for `@Native` compatibility
Daco Harkes

Done

File runtime/lib/ffi_dynamic_library.cc
Line 495, Patchset 5: Exceptions::ThrowUnsupportedError(
Daco Harkes . resolved

I'd probably read the `error` value here and set it inside the helper function.

(We'll still need the if to branch correctly to a unsupported error instead of argument error 👍)

Shikhar Soni

PTAL

Daco Harkes

Done

Line 495, Patchset 8: native_assets_api->dlopen != nullptr;
Daco Harkes . resolved

The second condition is not needed right?

Shikhar

It is, because `LoadAssetLibraryFromKernelMapping` can also return errors, so distinguish errors from that path and `UnsupportedError`...


I think I should return an `unsupported` flag from `LoadAssetLibrary`, that would be more clean.

Daco Harkes

Acknowledged

Line 499, Patchset 5: const String& msg = String::Handle(String::NewFormatted(
Daco Harkes . resolved

Use `native_assets_api->available_assets` if available for the error message so that we print which assets are available. (In case someone does a typo in the asset id.)

Shikhar Soni

PTAL

Daco Harkes

Done

Open in Gerrit

Related details

Attention is currently required from:
  • Shikhar
  • Shikhar Soni
  • Slava Egorov
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement satisfiedCode-Review
  • requirement satisfiedCommit-Message-Has-TEST
  • requirement satisfiedCore-Library-Review
  • requirement satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: If9b37249cffd2a454644f11259c089f95f4d1d69
Gerrit-Change-Number: 511960
Gerrit-PatchSet: 9
Gerrit-Owner: Shikhar Soni <shikh...@google.com>
Gerrit-Reviewer: Daco Harkes <dacoh...@google.com>
Gerrit-Reviewer: Slava Egorov <veg...@google.com>
Gerrit-CC: Shikhar <shikha...@gmail.com>
Gerrit-Attention: Shikhar <shikha...@gmail.com>
Gerrit-Attention: Slava Egorov <veg...@google.com>
Gerrit-Attention: Shikhar Soni <shikh...@google.com>
Gerrit-Comment-Date: Tue, 23 Jun 2026 15:09:13 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: Yes
Comment-In-Reply-To: Shikhar <shikha...@gmail.com>
satisfied_requirement
open
diffy

Slava Egorov (Gerrit)

unread,
Jun 24, 2026, 6:38:16 AM (2 days ago) Jun 24
to Shikhar Soni, Daco Harkes, dart-...@luci-project-accounts.iam.gserviceaccount.com, dart-dc-te...@google.com, rev...@dartlang.org, vm-...@dartlang.org
Attention needed from Daco Harkes and Shikhar Soni

Slava Egorov added 3 comments

File runtime/include/dart_api.h
Line 3401, Patchset 9 (Latest): bool* can_be_closed,
Slava Egorov . unresolved

I sense some API design issue here: we have hooks for `dlopen` and `dlsym` but not for `dlclose`. I think a better way to do this would be to actually have a hook for `dlclose` which returns appropriate error on unclosable handles returned by `dlopen`.

Line 3400, Patchset 9 (Latest): bool* asset_found,
Slava Egorov . unresolved

It seems that this is only relevant for error reporting? Why have it then - let the embedder put `No asset ${id} found` into error.

File sdk/lib/ffi/dynamic_library.dart
Line 47, Patchset 9 (Latest): external factory DynamicLibrary.openFromAssetId(String assetId);
Slava Egorov . unresolved

Maybe better name is just `DynamicLibrary.openAsset` or `DynamicLibrary.fromAsset` or `DynamicLibrary.asset` or something like this, `openFromAssetId` is a mouthful.

Open in Gerrit

Related details

Attention is currently required from:
  • Daco Harkes
  • Shikhar Soni
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement satisfiedCode-Review
  • requirement satisfiedCommit-Message-Has-TEST
  • requirement satisfiedCore-Library-Review
  • requirement satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: If9b37249cffd2a454644f11259c089f95f4d1d69
Gerrit-Change-Number: 511960
Gerrit-PatchSet: 9
Gerrit-Owner: Shikhar Soni <shikh...@google.com>
Gerrit-Reviewer: Daco Harkes <dacoh...@google.com>
Gerrit-Reviewer: Slava Egorov <veg...@google.com>
Gerrit-Attention: Daco Harkes <dacoh...@google.com>
Gerrit-Attention: Shikhar Soni <shikh...@google.com>
Gerrit-Comment-Date: Wed, 24 Jun 2026 10:38:08 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
satisfied_requirement
open
diffy

Daco Harkes (Gerrit)

unread,
Jun 24, 2026, 6:53:31 AM (2 days ago) Jun 24
to Shikhar Soni, dart-...@luci-project-accounts.iam.gserviceaccount.com, Slava Egorov, dart-dc-te...@google.com, rev...@dartlang.org, vm-...@dartlang.org
Attention needed from Shikhar Soni

Daco Harkes added 3 comments

Patchset-level comments
File runtime/include/dart_api.h
Line 3401, Patchset 9 (Latest): bool* can_be_closed,
Slava Egorov . unresolved

I sense some API design issue here: we have hooks for `dlopen` and `dlsym` but not for `dlclose`. I think a better way to do this would be to actually have a hook for `dlclose` which returns appropriate error on unclosable handles returned by `dlopen`.

Daco Harkes

Good point. If we someone adds a new operating system with different system calls, it would be a different close system call!

Related issue which mentions the need for having a dlclose in the embedder API: https://github.com/dart-lang/sdk/issues/55521

We'll need to add an extra bool to the DynamicLibrary class to register that it was created via the embedder API for code assets, so that close can forward to that.

File sdk/lib/ffi/dynamic_library.dart
Line 47, Patchset 9 (Latest): external factory DynamicLibrary.openFromAssetId(String assetId);
Slava Egorov . unresolved

Maybe better name is just `DynamicLibrary.openAsset` or `DynamicLibrary.fromAsset` or `DynamicLibrary.asset` or something like this, `openFromAssetId` is a mouthful.

Daco Harkes

`DynamicLibrary.openCodeAsset` or `DynamicLibrary.codeAsset` to be consistent with https://dart.dev/tools/hooks and https://pub.dev/packages/code_assets terminology.

Maybe the latter.

Open in Gerrit

Related details

Attention is currently required from:
  • Shikhar Soni
Submit Requirements:
  • requirement satisfiedCode-Owners
  • requirement satisfiedCode-Review
  • requirement satisfiedCommit-Message-Has-TEST
  • requirement satisfiedCore-Library-Review
  • requirement satisfiedReview-Enforcement
Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
Gerrit-MessageType: comment
Gerrit-Project: sdk
Gerrit-Branch: main
Gerrit-Change-Id: If9b37249cffd2a454644f11259c089f95f4d1d69
Gerrit-Change-Number: 511960
Gerrit-PatchSet: 9
Gerrit-Owner: Shikhar Soni <shikh...@google.com>
Gerrit-Reviewer: Daco Harkes <dacoh...@google.com>
Gerrit-Reviewer: Slava Egorov <veg...@google.com>
Gerrit-Attention: Shikhar Soni <shikh...@google.com>
Gerrit-Comment-Date: Wed, 24 Jun 2026 10:53:22 +0000
Gerrit-HasComments: Yes
Gerrit-Has-Labels: No
Comment-In-Reply-To: Slava Egorov <veg...@google.com>
satisfied_requirement
open
diffy

Shikhar Soni (Gerrit)

unread,
Jun 25, 2026, 5:20:55 AM (yesterday) Jun 25
to Daco Harkes, dart-...@luci-project-accounts.iam.gserviceaccount.com, Slava Egorov, dart-dc-te...@google.com, rev...@dartlang.org, vm-...@dartlang.org
Attention needed from Daco Harkes and Slava Egorov

Shikhar Soni added 3 comments

File runtime/include/dart_api.h
Line 3401, Patchset 9: bool* can_be_closed,
Slava Egorov . unresolved

I sense some API design issue here: we have hooks for `dlopen` and `dlsym` but not for `dlclose`. I think a better way to do this would be to actually have a hook for `dlclose` which returns appropriate error on unclosable handles returned by `dlopen`.

Daco Harkes

Good point. If we someone adds a new operating system with different system calls, it would be a different close system call!

Related issue which mentions the need for having a dlclose in the embedder API: https://github.com/dart-lang/sdk/issues/55521

We'll need to add an extra bool to the DynamicLibrary class to register that it was created via the embedder API for code assets, so that close can forward to that.

Shikhar Soni

Added a `dlcose` callback and a on `DyanimcLibrary` flag to remember when the handle came from `NativeAssetApi`, so close now goes back throught the embedder.
PTAL if this looks good.

Line 3400, Patchset 9: bool* asset_found,
Slava Egorov . resolved

It seems that this is only relevant for error reporting? Why have it then - let the embedder put `No asset ${id} found` into error.

Shikhar Soni

Done

File sdk/lib/ffi/dynamic_library.dart
Line 47, Patchset 9: external factory DynamicLibrary.openFromAssetId(String assetId);
Slava Egorov . resolved

Maybe better name is just `DynamicLibrary.openAsset` or `DynamicLibrary.fromAsset` or `DynamicLibrary.asset` or something like this, `openFromAssetId` is a mouthful.

Daco Harkes

`DynamicLibrary.openCodeAsset` or `DynamicLibrary.codeAsset` to be consistent with https://dart.dev/tools/hooks and https://pub.dev/packages/code_assets terminology.

Maybe the latter.

Shikhar Soni

Acknowledged

Open in Gerrit

Related details

Attention is currently required from:
  • Daco Harkes
  • Slava Egorov
Submit Requirements:
    • requirement is not satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement satisfiedCommit-Message-Has-TEST
    • requirement satisfiedCore-Library-Review
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: sdk
    Gerrit-Branch: main
    Gerrit-Change-Id: If9b37249cffd2a454644f11259c089f95f4d1d69
    Gerrit-Change-Number: 511960
    Gerrit-PatchSet: 9
    Gerrit-Owner: Shikhar Soni <shikh...@google.com>
    Gerrit-Reviewer: Daco Harkes <dacoh...@google.com>
    Gerrit-Reviewer: Slava Egorov <veg...@google.com>
    Gerrit-Attention: Slava Egorov <veg...@google.com>
    Gerrit-Attention: Daco Harkes <dacoh...@google.com>
    Gerrit-Comment-Date: Thu, 25 Jun 2026 09:20:50 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Slava Egorov <veg...@google.com>
    Comment-In-Reply-To: Daco Harkes <dacoh...@google.com>
    unsatisfied_requirement
    satisfied_requirement
    open
    diffy

    Shikhar Soni (Gerrit)

    unread,
    Jun 25, 2026, 5:22:07 AM (yesterday) Jun 25
    to Daco Harkes, dart-...@luci-project-accounts.iam.gserviceaccount.com, Slava Egorov, dart-dc-te...@google.com, rev...@dartlang.org, vm-...@dartlang.org
    Attention needed from Daco Harkes and Slava Egorov

    Shikhar Soni added 1 comment

    File runtime/include/dart_api.h
    Line 3401, Patchset 9: bool* can_be_closed,
    Slava Egorov . unresolved

    I sense some API design issue here: we have hooks for `dlopen` and `dlsym` but not for `dlclose`. I think a better way to do this would be to actually have a hook for `dlclose` which returns appropriate error on unclosable handles returned by `dlopen`.

    Daco Harkes

    Good point. If we someone adds a new operating system with different system calls, it would be a different close system call!

    Related issue which mentions the need for having a dlclose in the embedder API: https://github.com/dart-lang/sdk/issues/55521

    We'll need to add an extra bool to the DynamicLibrary class to register that it was created via the embedder API for code assets, so that close can forward to that.

    Shikhar Soni

    Added a `dlcose` callback and a on `DyanimcLibrary` flag to remember when the handle came from `NativeAssetApi`, so close now goes back throught the embedder.
    PTAL if this looks good.

    Shikhar Soni

    PS: Patchset 10

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Daco Harkes
    • Slava Egorov
    Submit Requirements:
    • requirement is not satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement satisfiedCommit-Message-Has-TEST
    • requirement satisfiedCore-Library-Review
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: sdk
    Gerrit-Branch: main
    Gerrit-Change-Id: If9b37249cffd2a454644f11259c089f95f4d1d69
    Gerrit-Change-Number: 511960
    Gerrit-PatchSet: 10
    Gerrit-Owner: Shikhar Soni <shikh...@google.com>
    Gerrit-Reviewer: Daco Harkes <dacoh...@google.com>
    Gerrit-Reviewer: Slava Egorov <veg...@google.com>
    Gerrit-Attention: Slava Egorov <veg...@google.com>
    Gerrit-Attention: Daco Harkes <dacoh...@google.com>
    Gerrit-Comment-Date: Thu, 25 Jun 2026 09:22:02 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Slava Egorov <veg...@google.com>
    Comment-In-Reply-To: Daco Harkes <dacoh...@google.com>
    Comment-In-Reply-To: Shikhar Soni <shikh...@google.com>
    unsatisfied_requirement
    satisfied_requirement
    open
    diffy

    Daco Harkes (Gerrit)

    unread,
    Jun 25, 2026, 6:16:49 AM (yesterday) Jun 25
    to Shikhar Soni, dart-...@luci-project-accounts.iam.gserviceaccount.com, Slava Egorov, dart-dc-te...@google.com, rev...@dartlang.org, vm-...@dartlang.org
    Attention needed from Shikhar Soni and Slava Egorov

    Daco Harkes added 2 comments

    File runtime/lib/ffi_dynamic_library.cc
    Line 234, Patchset 10 (Latest): } else if (!dlib.CanBeClosed()) {
    Daco Harkes . unresolved

    @veg...@google.com The original implementation stores `can_be_closed` in the Dart object. It would be kind of weird if we store it in the object for `DynamicLibrary.process()` but not for `DynamicLibrary.codeAsset(assetThatResolvesToProcess)`. Would you suggest to refactor the existing implementation to unconditionally call `close` as well?

    That means that `Utils::UnloadDynamicLibrary` needs to do the closing of `DynamicLibrary.process` and `DynamicLibrary.executable()`.

    We can check for `RTLD_DEFAULT` and `kWindowsDynamicLibraryProcessPtr` and `LoadDynamicLibrary(nullptr)` equality and return the error from `Utils::UnloadDynamicLibrary`.

    Line 277, Patchset 10 (Latest): if (dlib.UseNativeAssetsApi()) {
    Daco Harkes . resolved

    Oh, good catch!

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Shikhar Soni
    • Slava Egorov
    Submit Requirements:
    • requirement is not satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement satisfiedCommit-Message-Has-TEST
    • requirement satisfiedCore-Library-Review
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: sdk
    Gerrit-Branch: main
    Gerrit-Change-Id: If9b37249cffd2a454644f11259c089f95f4d1d69
    Gerrit-Change-Number: 511960
    Gerrit-PatchSet: 10
    Gerrit-Owner: Shikhar Soni <shikh...@google.com>
    Gerrit-Reviewer: Daco Harkes <dacoh...@google.com>
    Gerrit-Reviewer: Slava Egorov <veg...@google.com>
    Gerrit-Attention: Slava Egorov <veg...@google.com>
    Gerrit-Attention: Shikhar Soni <shikh...@google.com>
    Gerrit-Comment-Date: Thu, 25 Jun 2026 10:16:43 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    unsatisfied_requirement
    satisfied_requirement
    open
    diffy

    Slava Egorov (Gerrit)

    unread,
    6:16 AM (28 minutes ago) 6:16 AM
    to Shikhar Soni, Daco Harkes, dart-...@luci-project-accounts.iam.gserviceaccount.com, dart-dc-te...@google.com, rev...@dartlang.org, vm-...@dartlang.org
    Attention needed from Shikhar Soni

    Slava Egorov added 4 comments

    File runtime/include/dart_api.h
    Line 3396, Patchset 10 (Latest):typedef void* (*Dart_NativeAssetsDlopenAssetIdV2)(const char* asset_id,
    Slava Egorov . unresolved

    This is now the same as `Dart_NativeAssetsDlopenAssetId` so you can just delete it and specify new behavior on `dlopen_v2`.

    But the question is: does behavior actually meaningfully differ between `dlopen` and `dlopen_v2`? Because I think they behave pretty much the same.

    File runtime/lib/ffi_dynamic_library.cc
    Line 234, Patchset 10 (Latest): } else if (!dlib.CanBeClosed()) {
    Daco Harkes . unresolved

    @veg...@google.com The original implementation stores `can_be_closed` in the Dart object. It would be kind of weird if we store it in the object for `DynamicLibrary.process()` but not for `DynamicLibrary.codeAsset(assetThatResolvesToProcess)`. Would you suggest to refactor the existing implementation to unconditionally call `close` as well?

    That means that `Utils::UnloadDynamicLibrary` needs to do the closing of `DynamicLibrary.process` and `DynamicLibrary.executable()`.

    We can check for `RTLD_DEFAULT` and `kWindowsDynamicLibraryProcessPtr` and `LoadDynamicLibrary(nullptr)` equality and return the error from `Utils::UnloadDynamicLibrary`.

    Slava Egorov

    I thought we would change `can_be_closed` field to become the function instead... To point to the close function which should be used (so that we could differentiate whether we need to call native assets API one or `Utils` one). If we want a short-cut we could make `nullptr` mean that it can't be closed.

    File runtime/vm/raw_object.h
    Line 3688, Patchset 10 (Latest): bool canBeClosed_;
    Slava Egorov . unresolved

    Instead of having `canBeClosed_` and `useNativeAssetsApi_` we should just have `Dart_NativeAssetsDlcloseCallback dlclose_;`.

    Line 3687, Patchset 10 (Latest): bool isClosed_;
    Slava Egorov . unresolved

    nit: style guide violation, must be `is_closed_` instead.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Shikhar Soni
    Submit Requirements:
    • requirement is not satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement satisfiedCommit-Message-Has-TEST
    • requirement satisfiedCore-Library-Review
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: sdk
    Gerrit-Branch: main
    Gerrit-Change-Id: If9b37249cffd2a454644f11259c089f95f4d1d69
    Gerrit-Change-Number: 511960
    Gerrit-PatchSet: 10
    Gerrit-Owner: Shikhar Soni <shikh...@google.com>
    Gerrit-Reviewer: Daco Harkes <dacoh...@google.com>
    Gerrit-Reviewer: Slava Egorov <veg...@google.com>
    Gerrit-Attention: Shikhar Soni <shikh...@google.com>
    Gerrit-Comment-Date: Fri, 26 Jun 2026 10:15:57 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    Comment-In-Reply-To: Daco Harkes <dacoh...@google.com>
    unsatisfied_requirement
    satisfied_requirement
    open
    diffy

    Daco Harkes (Gerrit)

    unread,
    6:22 AM (22 minutes ago) 6:22 AM
    to Shikhar Soni, dart-...@luci-project-accounts.iam.gserviceaccount.com, Slava Egorov, dart-dc-te...@google.com, rev...@dartlang.org, vm-...@dartlang.org
    Attention needed from Shikhar Soni

    Daco Harkes added 2 comments

    File runtime/lib/ffi_dynamic_library.cc
    Line 234, Patchset 10 (Latest): } else if (!dlib.CanBeClosed()) {
    Daco Harkes . unresolved

    @veg...@google.com The original implementation stores `can_be_closed` in the Dart object. It would be kind of weird if we store it in the object for `DynamicLibrary.process()` but not for `DynamicLibrary.codeAsset(assetThatResolvesToProcess)`. Would you suggest to refactor the existing implementation to unconditionally call `close` as well?

    That means that `Utils::UnloadDynamicLibrary` needs to do the closing of `DynamicLibrary.process` and `DynamicLibrary.executable()`.

    We can check for `RTLD_DEFAULT` and `kWindowsDynamicLibraryProcessPtr` and `LoadDynamicLibrary(nullptr)` equality and return the error from `Utils::UnloadDynamicLibrary`.

    Slava Egorov

    I thought we would change `can_be_closed` field to become the function instead... To point to the close function which should be used (so that we could differentiate whether we need to call native assets API one or `Utils` one). If we want a short-cut we could make `nullptr` mean that it can't be closed.

    Daco Harkes

    We can't just blindly route it to the function for `DynamicLibrary`s created via the other constructors. They are created by the VM not by the embedder. So you the ones created via native assets can be routed to that function.

    File runtime/vm/raw_object.h
    Slava Egorov . unresolved

    Instead of having `canBeClosed_` and `useNativeAssetsApi_` we should just have `Dart_NativeAssetsDlcloseCallback dlclose_;`.

    Daco Harkes

    No. `DynamicLibrary` created with `DynamicLibrary.open` are not created via the embedder API, so they should not be closed via the embedder API.

    But we can close them via `Utils::UnloadDynamicLibrary` as long as that throws an error on trying to close the process and executable.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Shikhar Soni
    Submit Requirements:
    • requirement is not satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement satisfiedCommit-Message-Has-TEST
    • requirement satisfiedCore-Library-Review
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: sdk
    Gerrit-Branch: main
    Gerrit-Change-Id: If9b37249cffd2a454644f11259c089f95f4d1d69
    Gerrit-Change-Number: 511960
    Gerrit-PatchSet: 10
    Gerrit-Owner: Shikhar Soni <shikh...@google.com>
    Gerrit-Reviewer: Daco Harkes <dacoh...@google.com>
    Gerrit-Reviewer: Slava Egorov <veg...@google.com>
    Gerrit-Attention: Shikhar Soni <shikh...@google.com>
    Gerrit-Comment-Date: Fri, 26 Jun 2026 10:22:27 +0000
    Gerrit-HasComments: Yes
    Gerrit-Has-Labels: No
    unsatisfied_requirement
    satisfied_requirement
    open
    diffy

    Daco Harkes (Gerrit)

    unread,
    6:32 AM (12 minutes ago) 6:32 AM
    to Shikhar Soni, dart-...@luci-project-accounts.iam.gserviceaccount.com, Slava Egorov, dart-dc-te...@google.com, rev...@dartlang.org, vm-...@dartlang.org
    Attention needed from Shikhar Soni

    Daco Harkes added 1 comment

    File runtime/lib/ffi_dynamic_library.cc
    Line 234, Patchset 10 (Latest): } else if (!dlib.CanBeClosed()) {
    Daco Harkes . unresolved

    @veg...@google.com The original implementation stores `can_be_closed` in the Dart object. It would be kind of weird if we store it in the object for `DynamicLibrary.process()` but not for `DynamicLibrary.codeAsset(assetThatResolvesToProcess)`. Would you suggest to refactor the existing implementation to unconditionally call `close` as well?

    That means that `Utils::UnloadDynamicLibrary` needs to do the closing of `DynamicLibrary.process` and `DynamicLibrary.executable()`.

    We can check for `RTLD_DEFAULT` and `kWindowsDynamicLibraryProcessPtr` and `LoadDynamicLibrary(nullptr)` equality and return the error from `Utils::UnloadDynamicLibrary`.

    Slava Egorov

    I thought we would change `can_be_closed` field to become the function instead... To point to the close function which should be used (so that we could differentiate whether we need to call native assets API one or `Utils` one). If we want a short-cut we could make `nullptr` mean that it can't be closed.

    Daco Harkes

    We can't just blindly route it to the function for `DynamicLibrary`s created via the other constructors. They are created by the VM not by the embedder. So you the ones created via native assets can be routed to that function.

    Daco Harkes

    We could add another `dlopen_legacy` to the embedder API and make all `DynamicLibrary.open` calls go there. And then route `DynamicLibrary.proccess` and `DynamicLibrary.executable` to the embedder API as well. Then everything would be embedder API.

    Open in Gerrit

    Related details

    Attention is currently required from:
    • Shikhar Soni
    Submit Requirements:
    • requirement is not satisfiedCode-Owners
    • requirement is not satisfiedCode-Review
    • requirement satisfiedCommit-Message-Has-TEST
    • requirement satisfiedCore-Library-Review
    • requirement is not satisfiedReview-Enforcement
    Inspect html for hidden footers to help with email filtering. To unsubscribe visit settings. DiffyGerrit
    Gerrit-MessageType: comment
    Gerrit-Project: sdk
    Gerrit-Branch: main
    Gerrit-Change-Id: If9b37249cffd2a454644f11259c089f95f4d1d69
    Gerrit-Change-Number: 511960
    Gerrit-PatchSet: 10
    Gerrit-Owner: Shikhar Soni <shikh...@google.com>
    Gerrit-Reviewer: Daco Harkes <dacoh...@google.com>
    Gerrit-Reviewer: Slava Egorov <veg...@google.com>
    Gerrit-Attention: Shikhar Soni <shikh...@google.com>
    Gerrit-Comment-Date: Fri, 26 Jun 2026 10:32:20 +0000
    unsatisfied_requirement
    satisfied_requirement
    open
    diffy
    Reply all
    Reply to author
    Forward
    0 new messages