blob: 32cabc6a7d3f22cef6f2b44a2b73574e361f036d [file] [log] [blame]
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
// All imports must be in all FFI patch files to not depend on the order
// the patches are applied.
import "dart:_internal" show patch;
import 'dart:typed_data' show TypedData;
DynamicLibrary _open(String name) native "Ffi_dl_open";
DynamicLibrary _processLibrary() native "Ffi_dl_processLibrary";
DynamicLibrary _executableLibrary() native "Ffi_dl_executableLibrary";
class DynamicLibrary {
factory name) {
return _open(name);
factory DynamicLibrary.process() => _processLibrary();
factory DynamicLibrary.executable() => _executableLibrary();
Pointer<T> lookup<T extends NativeType>(String symbolName)
native "Ffi_dl_lookup";
// The real implementation of this function lives in FfiUseSitesTransformer
// for interface calls. Only dynamic calls (which are illegal) reach this
// implementation.
F lookupFunction<T extends Function, F extends Function>(String symbolName) {
throw UnsupportedError(
"Dynamic invocation of lookupFunction is not supported.");
// TODO(dacoharkes): Expose this to users, or extend Pointer?
int getHandle() native "Ffi_dl_getHandle";
bool operator ==(other) {
if (other == null) return false;
return getHandle() == other.getHandle();
int get hashCode {
return getHandle().hashCode;
Pointer<Void> get handle => Pointer.fromAddress(getHandle());