-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathjni_wrapper.cc
80 lines (69 loc) · 2.5 KB
/
jni_wrapper.cc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
#include <jni.h>
#include <cstddef>
#include "common_macros.h"
#include "clear_cache.h"
#include "syscall_ext.h"
extern "C" JNIEXPORT void JNICALL
NativeBridge_breakpoint
(JNIEnv* env, jclass _k) {
__builtin_debugtrap();
}
extern "C" JNIEXPORT jlong JNICALL
NativeBridge_nativeSyscall
(JNIEnv* env, jclass _k, jint number, jlong arg1, jlong arg2, jlong arg3, jlong arg4, jlong arg5, jlong arg6) {
return (jlong) syscall_ext(number, (uintptr_t) arg1, (uintptr_t) arg2, (uintptr_t) arg3,
(uintptr_t) arg4, (uintptr_t) arg5, (uintptr_t) arg6);
}
extern "C" JNIEXPORT void JNICALL
NativeBridge_nativeClearCache
(JNIEnv* env, jclass _, jlong address, jlong size) {
void* start = (void*) address;
auto sz = (size_t) size;
void* end = (void*) ((uintptr_t) start + sz);
__clear_cache(start, end);
}
extern "C" JNIEXPORT jlong JNICALL
NativeBridge_nativeCallPointerFunction0
(JNIEnv* env, jclass _, jlong function) {
typedef void* (* FunctionType)();
auto f = (FunctionType) function;
return (jlong) f();
}
extern "C" JNIEXPORT jlong JNICALL
NativeBridge_nativeCallPointerFunction1
(JNIEnv* env, jclass _, jlong function, jlong arg1) {
typedef void* (* FunctionType)(void*);
auto f = (FunctionType) function;
return (jlong) f((void*) arg1);
}
extern "C" JNIEXPORT jlong JNICALL
NativeBridge_nativeCallPointerFunction2
(JNIEnv* env, jclass _, jlong function, jlong arg1, jlong arg2) {
typedef void* (* FunctionType)(void*, void*);
auto f = (FunctionType) function;
return (jlong) f((void*) arg1, (void*) arg2);
}
extern "C" JNIEXPORT jlong JNICALL
NativeBridge_nativeCallPointerFunction3
(JNIEnv* env, jclass _, jlong function, jlong arg1, jlong arg2, jlong arg3) {
typedef void* (* FunctionType)(void*, void*, void*);
auto f = (FunctionType) function;
return (jlong) f((void*) arg1, (void*) arg2, (void*) arg3);
}
extern "C" JNIEXPORT jlong JNICALL
NativeBridge_nativeCallPointerFunction4
(JNIEnv* env, jclass _, jlong function, jlong arg1, jlong arg2, jlong arg3, jlong arg4) {
typedef void* (* FunctionType)(void*, void*, void*, void*);
auto f = (FunctionType) function;
return (jlong) f((void*) arg1, (void*) arg2, (void*) arg3, (void*) arg4);
}
extern "C" JNIEXPORT jlong JNICALL
NativeBridge_nativeGetJavaVM
(JNIEnv* env, jclass _) {
JavaVM* vm = nullptr;
if (env->GetJavaVM(&vm) == 0) {
return (jlong) vm;
} else {
return 0;
}
}