Search in sources :

Example 1 with NativeClosureHandle

use of com.oracle.svm.truffle.nfi.LibFFI.NativeClosureHandle in project graal by oracle.

the class NativeClosure method prepareClosure.

static Target_com_oracle_truffle_nfi_impl_ClosureNativePointer prepareClosure(Target_com_oracle_truffle_nfi_impl_NFIContext ctx, Target_com_oracle_truffle_nfi_impl_LibFFISignature signature, CallTarget callTarget, ffi_closure_callback callback) {
    NativeClosure closure = new NativeClosure(callTarget, signature);
    NativeClosureHandle handle = ImageSingletons.lookup(TruffleNFISupport.class).createClosureHandle(closure);
    WordPointer codePtr = StackValue.get(SizeOf.get(WordPointer.class));
    ClosureData data = ffi_closure_alloc(SizeOf.unsigned(ClosureData.class), codePtr);
    data.setNativeClosureHandle(handle);
    data.setIsolate(CEntryPointContext.getCurrentIsolate());
    PointerBase code = codePtr.read();
    LibFFI.ffi_prep_closure_loc(data.ffiClosure(), WordFactory.pointer(signature.cif), callback, data, code);
    return ctx.createClosureNativePointer(data.rawValue(), code.rawValue(), callTarget, signature);
}
Also used : NativeClosureHandle(com.oracle.svm.truffle.nfi.LibFFI.NativeClosureHandle) WordPointer(org.graalvm.nativeimage.c.type.WordPointer) PointerBase(org.graalvm.word.PointerBase) ClosureData(com.oracle.svm.truffle.nfi.LibFFI.ClosureData)

Aggregations

ClosureData (com.oracle.svm.truffle.nfi.LibFFI.ClosureData)1 NativeClosureHandle (com.oracle.svm.truffle.nfi.LibFFI.NativeClosureHandle)1 WordPointer (org.graalvm.nativeimage.c.type.WordPointer)1 PointerBase (org.graalvm.word.PointerBase)1