Search in sources :

Example 1 with NativeTruffleContext

use of com.oracle.svm.truffle.nfi.NativeAPI.NativeTruffleContext in project graal by oracle.

the class Target_com_oracle_truffle_nfi_impl_NFIContext method executeNative.

@Substitute
void executeNative(long cif, long functionPointer, byte[] primArgs, int patchCount, int[] patchOffsets, Object[] objArgs, byte[] ret) {
    try (LocalNativeScope scope = TruffleNFISupport.createLocalScope(patchCount);
        PinnedObject retBuffer = PinnedObject.create(ret)) {
        NativeTruffleContext ctx = WordFactory.pointer(nativeContext);
        ffi_cif ffiCif = WordFactory.pointer(cif);
        ExecuteHelper.execute(ctx, ffiCif, retBuffer.addressOfArrayElement(0), functionPointer, primArgs, patchCount, patchOffsets, objArgs, scope);
    }
}
Also used : LibFFI.ffi_cif(com.oracle.svm.truffle.nfi.libffi.LibFFI.ffi_cif) PinnedObject(org.graalvm.nativeimage.PinnedObject) NativeTruffleContext(com.oracle.svm.truffle.nfi.NativeAPI.NativeTruffleContext) Substitute(com.oracle.svm.core.annotate.Substitute)

Example 2 with NativeTruffleContext

use of com.oracle.svm.truffle.nfi.NativeAPI.NativeTruffleContext in project graal by oracle.

the class Target_com_oracle_truffle_nfi_impl_NFIContext method executeObject.

@Substitute
Object executeObject(long cif, long functionPointer, byte[] primArgs, int patchCount, int[] patchOffsets, Object[] objArgs) {
    try (LocalNativeScope scope = TruffleNFISupport.createLocalScope(patchCount)) {
        NativeTruffleContext ctx = WordFactory.pointer(nativeContext);
        ffi_cif ffiCif = WordFactory.pointer(cif);
        WordPointer retPtr = StackValue.get(8);
        ExecuteHelper.execute(ctx, ffiCif, retPtr, functionPointer, primArgs, patchCount, patchOffsets, objArgs, scope);
        return ImageSingletons.lookup(TruffleNFISupport.class).resolveHandle(retPtr.read());
    }
}
Also used : LibFFI.ffi_cif(com.oracle.svm.truffle.nfi.libffi.LibFFI.ffi_cif) WordPointer(org.graalvm.nativeimage.c.type.WordPointer) NativeTruffleContext(com.oracle.svm.truffle.nfi.NativeAPI.NativeTruffleContext) Substitute(com.oracle.svm.core.annotate.Substitute)

Example 3 with NativeTruffleContext

use of com.oracle.svm.truffle.nfi.NativeAPI.NativeTruffleContext in project graal by oracle.

the class Target_com_oracle_truffle_nfi_impl_NFIContext method executePrimitive.

@Substitute
long executePrimitive(long cif, long functionPointer, byte[] primArgs, int patchCount, int[] patchOffsets, Object[] objArgs) {
    try (LocalNativeScope scope = TruffleNFISupport.createLocalScope(patchCount)) {
        NativeTruffleContext ctx = WordFactory.pointer(nativeContext);
        ffi_cif ffiCif = WordFactory.pointer(cif);
        CLongPointer retPtr = StackValue.get(8);
        ExecuteHelper.execute(ctx, ffiCif, retPtr, functionPointer, primArgs, patchCount, patchOffsets, objArgs, scope);
        return retPtr.read();
    }
}
Also used : LibFFI.ffi_cif(com.oracle.svm.truffle.nfi.libffi.LibFFI.ffi_cif) CLongPointer(org.graalvm.nativeimage.c.type.CLongPointer) NativeTruffleContext(com.oracle.svm.truffle.nfi.NativeAPI.NativeTruffleContext) Substitute(com.oracle.svm.core.annotate.Substitute)

Example 4 with NativeTruffleContext

use of com.oracle.svm.truffle.nfi.NativeAPI.NativeTruffleContext in project graal by oracle.

the class Target_com_oracle_truffle_nfi_impl_NFIContext method initializeNativeContext.

// Checkstyle: resume
@Substitute
private long initializeNativeContext() {
    TruffleNFISupport support = ImageSingletons.lookup(TruffleNFISupport.class);
    NativeTruffleContext ret = UnmanagedMemory.malloc(SizeOf.get(NativeTruffleContext.class));
    ret.setContextHandle(support.createContextHandle(this));
    NFIInitialization.initializeContext(ret);
    return ret.rawValue();
}
Also used : NativeTruffleContext(com.oracle.svm.truffle.nfi.NativeAPI.NativeTruffleContext) Substitute(com.oracle.svm.core.annotate.Substitute)

Example 5 with NativeTruffleContext

use of com.oracle.svm.truffle.nfi.NativeAPI.NativeTruffleContext in project graal by oracle.

the class Target_com_oracle_truffle_nfi_impl_NFIContext method initializeNativeEnv.

@Substitute
private static long initializeNativeEnv(long context) {
    NativeTruffleContext ctx = WordFactory.pointer(context);
    NativeTruffleEnv env = UnmanagedMemory.malloc(SizeOf.get(NativeTruffleEnv.class));
    NFIInitialization.initializeEnv(env, ctx);
    return env.rawValue();
}
Also used : NativeTruffleEnv(com.oracle.svm.truffle.nfi.NativeAPI.NativeTruffleEnv) NativeTruffleContext(com.oracle.svm.truffle.nfi.NativeAPI.NativeTruffleContext) Substitute(com.oracle.svm.core.annotate.Substitute)

Aggregations

Substitute (com.oracle.svm.core.annotate.Substitute)6 NativeTruffleContext (com.oracle.svm.truffle.nfi.NativeAPI.NativeTruffleContext)6 LibFFI.ffi_cif (com.oracle.svm.truffle.nfi.libffi.LibFFI.ffi_cif)3 NativeTruffleEnv (com.oracle.svm.truffle.nfi.NativeAPI.NativeTruffleEnv)1 PinnedObject (org.graalvm.nativeimage.PinnedObject)1 CLongPointer (org.graalvm.nativeimage.c.type.CLongPointer)1 WordPointer (org.graalvm.nativeimage.c.type.WordPointer)1