Search in sources :

Example 31 with Substitute

use of com.oracle.svm.core.annotate.Substitute 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 32 with Substitute

use of com.oracle.svm.core.annotate.Substitute 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 33 with Substitute

use of com.oracle.svm.core.annotate.Substitute in project graal by oracle.

the class Target_com_oracle_truffle_nfi_impl_NFIContext method lookup.

@Substitute
@TruffleBoundary
static long lookup(@SuppressWarnings("unused") long nativeContext, long library, String name) {
    // clear previous error
    Dlfcn.dlerror();
    PointerBase ret;
    if (library == 0) {
        ret = PosixUtils.dlsym(Dlfcn.RTLD_DEFAULT(), name);
    } else {
        ret = PosixUtils.dlsym(WordFactory.pointer(library), name);
    }
    if (ret.equal(WordFactory.zero())) {
        CompilerDirectives.transferToInterpreter();
        String error = PosixUtils.dlerror();
        if (error != null) {
            throw new UnsatisfiedLinkError(error);
        }
    }
    return ret.rawValue();
}
Also used : PointerBase(org.graalvm.word.PointerBase) TruffleBoundary(com.oracle.truffle.api.CompilerDirectives.TruffleBoundary) Substitute(com.oracle.svm.core.annotate.Substitute)

Example 34 with Substitute

use of com.oracle.svm.core.annotate.Substitute 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 35 with Substitute

use of com.oracle.svm.core.annotate.Substitute in project graal by oracle.

the class Target_com_oracle_truffle_nfi_impl_NFIContext method prepareSignature.

@Substitute
@SuppressWarnings("static-method")
long prepareSignature(Target_com_oracle_truffle_nfi_impl_LibFFIType retType, Target_com_oracle_truffle_nfi_impl_LibFFIType... args) {
    CifData data = PrepareHelper.prepareArgs(args);
    int ret = LibFFI.ffi_prep_cif(data.cif(), LibFFI.FFI_DEFAULT_ABI(), WordFactory.unsigned(args.length), WordFactory.pointer(retType.type), data.args());
    return PrepareHelper.checkRet(data, ret);
}
Also used : CifData(com.oracle.svm.truffle.nfi.NativeSignature.CifData) Substitute(com.oracle.svm.core.annotate.Substitute)

Aggregations

Substitute (com.oracle.svm.core.annotate.Substitute)69 CCharPointer (org.graalvm.nativeimage.c.type.CCharPointer)18 SocketException (java.net.SocketException)11 IOException (java.io.IOException)10 CIntPointer (org.graalvm.nativeimage.c.type.CIntPointer)10 PinnedObject (org.graalvm.nativeimage.PinnedObject)9 Util_java_io_FileDescriptor (com.oracle.svm.core.posix.PosixOSInterface.Util_java_io_FileDescriptor)8 FileDescriptor (java.io.FileDescriptor)8 CCharPointerHolder (org.graalvm.nativeimage.c.type.CTypeConversion.CCharPointerHolder)8 ServerSocket (java.net.ServerSocket)7 Socket (com.oracle.svm.core.posix.headers.Socket)6 NativeTruffleContext (com.oracle.svm.truffle.nfi.NativeAPI.NativeTruffleContext)6 SignedWord (org.graalvm.word.SignedWord)6 InterruptedIOException (java.io.InterruptedIOException)5 Time.timeval (com.oracle.svm.core.posix.headers.Time.timeval)4 Uninterruptible (com.oracle.svm.core.annotate.Uninterruptible)3 Stat.fstat (com.oracle.svm.core.posix.headers.Stat.fstat)3 Stat.stat (com.oracle.svm.core.posix.headers.Stat.stat)3 Time.timezone (com.oracle.svm.core.posix.headers.Time.timezone)3 LibFFI.ffi_cif (com.oracle.svm.truffle.nfi.libffi.LibFFI.ffi_cif)3