Skip to content

[vm/ffi] Expose dart_api.h and dart_native_api.h via dart:ffi? #40607

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dcharkes opened this issue Feb 12, 2020 · 1 comment
Closed

[vm/ffi] Expose dart_api.h and dart_native_api.h via dart:ffi? #40607

dcharkes opened this issue Feb 12, 2020 · 1 comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-ffi

Comments

@dcharkes
Copy link
Contributor

We could expose some symbols from dart_native_api.h and dart_api.h via dart:ffi.

This would solve two problems:

This would change the usage of dart_api.h and dart_native_api.h to manual dynamic linking passing back function pointers.

Static linking (current situation)

#include "include/dart_api.h"
#include "include/dart_native_api.h"

void SomeCode(){
  const bool result = Dart_PostCObject(send_port, &dart_object);
}

Manual dynamic linking (proposal)

// For the typedefs, but don't use the function pointers.
#include "include/dart_api.h"
#include "include/dart_native_api.h"

typedef bool (*Dart_PostCObjectType)(Dart_Port port_id, Dart_CObject* message);
Dart_PostCObjectType Dart_PostCObject_;

DART_EXPORT void RegisterDart_PostCObject(
    Dart_PostCObjectType function_pointer) {
  Dart_PostCObject_ = function_pointer;
}

void someCode(Dart_Port send_port, Dart_CObject dart_object) {
  const bool result = Dart_PostCObject_(send_port, &dart_object);
}
// dart:ffi
external Pointer<NativeFunction<...>> nativeApiDart_PostCObjectAddess();

// user code
final registerDart_PostCObject = dl.lookupFunction<
        Void Function(Pointer<NativeFunction<...>> functionPointer),
        void Function(Pointer<NativeFunction<...>> functionPointer)>(
    'RegisterDart_PostCObject');

registerDart_PostCObject(nativeApiDart_PostCObjectAddess());

cc @mkustermann @mraleph @derolf

@dcharkes dcharkes added area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-ffi labels Feb 12, 2020
@derolf
Copy link

derolf commented Feb 12, 2020

Exposing those into Dart is also an option I thought about.

I could then pass them down to my native library.

That way also the native-finalizer topic can be solved easily.

flutter/flutter#47061

dart-bot pushed a commit that referenced this issue Feb 28, 2020
This enables dynamic linking of the symbols in dart_native_api.h to work around the Windows linking issue and Dart embedders not exposing symbols.

Issue: #40607
Closes: #40564

Change-Id: I6f797cc915b53ec63fa5953529f17c40e52a2aed
Cq-Include-Trybots: luci.dart.try:vm-ffi-android-debug-arm-try,vm-ffi-android-debug-arm64-try,app-kernel-linux-debug-x64-try,vm-kernel-linux-debug-ia32-try,vm-kernel-win-debug-x64-try,vm-kernel-win-debug-ia32-try,vm-kernel-precomp-linux-debug-x64-try,vm-dartkb-linux-release-x64-abi-try,vm-kernel-precomp-android-release-arm64-try,vm-kernel-asan-linux-release-x64-try,vm-kernel-linux-release-simarm-try,vm-kernel-linux-release-simarm64-try,vm-kernel-precomp-android-release-arm_x64-try,vm-kernel-precomp-obfuscate-linux-release-x64-try,dart-sdk-linux-try,analyzer-analysis-server-linux-try,analyzer-linux-release-try,front-end-linux-release-x64-try,vm-kernel-precomp-win-release-x64-try
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/136962
Commit-Queue: Daco Harkes <[email protected]>
Reviewed-by: Vyacheslav Egorov <[email protected]>
Reviewed-by: Martin Kustermann <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. library-ffi
Projects
None yet
Development

No branches or pull requests

2 participants