Skip to content

Commit

Permalink
Fix runtime issues for native-image on AMD64
Browse files Browse the repository at this point in the history
Note: the Arena.ofConfined() change should probably not be merged to `master`,
but is currently necessary to work with native-image.
  • Loading branch information
msgilligan committed Mar 22, 2024
1 parent 4db5314 commit 4e96bbc
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
3 changes: 2 additions & 1 deletion secp256k1-examples-java/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ dependencies {
implementation project(':secp256k1-bouncy')
implementation project(':secp256k1-foreign')

implementation group: 'org.graalvm.nativeimage', name: 'library-support', version: '24.0.0'
// This is only needed for ForeignRegistrationFeature and the native-image build
implementation group: 'org.graalvm.sdk', name: 'nativeimage', version: '24.0.0'
}

jar {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,20 @@
/**
*
*/
public class ForeignRegistrationFeature {
public class ForeignRegistrationFeature implements Feature {
public void duringSetup(Feature.DuringSetupAccess access) {
RuntimeForeignAccess.registerForDowncall(FunctionDescriptor.ofVoid());
//RuntimeForeignAccess.registerForDowncall(FunctionDescriptor.ofVoid(), Linker.Option.isTrivial());
RuntimeForeignAccess.registerForDowncall(FunctionDescriptor.of(JAVA_INT, JAVA_INT, JAVA_INT));
RuntimeForeignAccess.registerForDowncall(FunctionDescriptor.of(JAVA_LONG, JAVA_INT));
RuntimeForeignAccess.registerForDowncall(FunctionDescriptor.of(JAVA_INT, JAVA_INT, JAVA_INT, JAVA_INT));
RuntimeForeignAccess.registerForDowncall(FunctionDescriptor.of(JAVA_INT, JAVA_LONG, JAVA_LONG, JAVA_LONG));
RuntimeForeignAccess.registerForDowncall(FunctionDescriptor.of(JAVA_INT, JAVA_LONG, JAVA_LONG, JAVA_LONG, JAVA_LONG, JAVA_LONG));
RuntimeForeignAccess.registerForDowncall(FunctionDescriptor.of(JAVA_INT, JAVA_LONG, JAVA_LONG, JAVA_LONG, JAVA_LONG, JAVA_LONG, JAVA_LONG));
RuntimeForeignAccess.registerForDowncall(FunctionDescriptor.of(JAVA_INT, JAVA_LONG, JAVA_LONG, JAVA_LONG, JAVA_LONG, JAVA_INT));
RuntimeForeignAccess.registerForDowncall(FunctionDescriptor.of(JAVA_INT, JAVA_LONG, JAVA_LONG));
RuntimeForeignAccess.registerForDowncall(FunctionDescriptor.ofVoid(JAVA_LONG, JAVA_LONG));
RuntimeForeignAccess.registerForDowncall(FunctionDescriptor.ofVoid(JAVA_LONG));
RuntimeForeignAccess.registerForDowncall(FunctionDescriptor.ofVoid(JAVA_INT, JAVA_INT));
RuntimeForeignAccess.registerForDowncall(FunctionDescriptor.of(ADDRESS, JAVA_INT, JAVA_INT), Linker.Option.firstVariadicArg(1));
RuntimeForeignAccess.registerForDowncall(FunctionDescriptor.ofVoid(JAVA_INT), Linker.Option.captureCallState("errno"));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ public Secp256k1Foreign(int flags) {
}

public Secp256k1Foreign(int flags, boolean randomize) {
arena = Arena.ofShared();
arena = Arena.ofConfined(); // Changed from `ofShared` for use in Graal native-image tools
/* Before we can call actual API functions, we need to create a "context". */
ctx = secp256k1_h.secp256k1_context_create(flags);

Expand Down

0 comments on commit 4e96bbc

Please sign in to comment.