Skip to content

Commit

Permalink
Register upcall stubs
Browse files Browse the repository at this point in the history
  • Loading branch information
Thihup committed May 27, 2024
1 parent 3886c15 commit 93428d4
Showing 1 changed file with 18 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import org.graalvm.nativeimage.hosted.RuntimeForeignAccess;

import java.lang.foreign.FunctionDescriptor;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;

import static java.lang.foreign.ValueLayout.*;
import static java.lang.foreign.ValueLayout.JAVA_INT;
Expand All @@ -24,5 +26,21 @@ public void duringSetup(DuringSetupAccess access) {
RuntimeForeignAccess.registerForDowncall(FunctionDescriptor.ofVoid(JAVA_INT, JAVA_INT, JAVA_INT, JAVA_FLOAT, JAVA_FLOAT, JAVA_FLOAT, JAVA_INT, JAVA_INT, ADDRESS, ADDRESS));
RuntimeForeignAccess.registerForDowncall(FunctionDescriptor.ofVoid(JAVA_FLOAT, ADDRESS, ADDRESS, ADDRESS, JAVA_INT, JAVA_INT, JAVA_INT, JAVA_INT, JAVA_INT, JAVA_FLOAT, JAVA_FLOAT, JAVA_INT, JAVA_INT, ADDRESS, ADDRESS));

try {
Method registerForUpcall = RuntimeForeignAccess.class.getDeclaredMethod("registerForUpcall", Object.class, Object[].class);

Object[] objects = new Object[0];
registerForUpcall.invoke(null, FunctionDescriptor.of(JAVA_INT, ADDRESS, ADDRESS, JAVA_INT, JAVA_INT, ADDRESS, ADDRESS), objects);
registerForUpcall.invoke(null, FunctionDescriptor.of(JAVA_INT, ADDRESS, ADDRESS, JAVA_INT, ADDRESS, ADDRESS), objects);
registerForUpcall.invoke(null, FunctionDescriptor.of(JAVA_INT, ADDRESS, ADDRESS, JAVA_INT, ADDRESS), objects);
registerForUpcall.invoke(null, FunctionDescriptor.of(JAVA_INT, ADDRESS, ADDRESS, JAVA_INT, ADDRESS), objects);
registerForUpcall.invoke(null, FunctionDescriptor.of(JAVA_INT, ADDRESS, ADDRESS, JAVA_INT, JAVA_INT, ADDRESS, ADDRESS, ADDRESS), objects);
registerForUpcall.invoke(null, FunctionDescriptor.of(JAVA_INT, JAVA_INT, ADDRESS), objects);
registerForUpcall.invoke(null, FunctionDescriptor.ofVoid(JAVA_INT, JAVA_INT, JAVA_INT, JAVA_FLOAT, JAVA_FLOAT, JAVA_FLOAT, JAVA_INT, JAVA_INT, ADDRESS, ADDRESS), objects);

} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException e) {
throw new RuntimeException(e);
}

}
}

0 comments on commit 93428d4

Please sign in to comment.