Skip to content

Instantly share code, notes, and snippets.

@Scrappers-glitch
Created January 27, 2023 22:40
Show Gist options
  • Save Scrappers-glitch/042a79698743f73e6c9a9678090fc145 to your computer and use it in GitHub Desktop.
Save Scrappers-glitch/042a79698743f73e6c9a9678090fc145 to your computer and use it in GitHub Desktop.
An example for how java native interface defines its headers and the implementation of java native apis
#include <stdio.h>
#include <stdlib.h>
/**
* Headers
*/
struct JNINativeInterface_ {
void *reserved0;
void *reserved1;
void *reserved2;
void *reserved3;
int (*GetVersion)(int* version);
};
/**
* Construct a memory reference type
*/
typedef struct JNINativeInterface_* JNIEnv;
/**
* Implementation
*/
int GetVersion(int* version) {
return 0b10 * (*version);
}
int main() {
struct JNINativeInterface_* jni_interface = (struct JNINativeInterface_*) calloc(1, sizeof(struct JNINativeInterface_));
JNIEnv* env = &jni_interface;
(*env)->GetVersion = &GetVersion;
int java = 8;
int jni_version = (*env)->GetVersion(&java);
printf("%i\n", jni_version);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment