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);
}
}
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());
}
}
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();
}
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();
}
}
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);
}
Aggregations