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
81
82
83
84
85
86
87
88
89
90
91
|
#include <stdlib.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdbool.h>
#include <assert.h>
#include <err.h>
#include <dlfcn.h>
#include "jvm/jni.h"
#include "linker/dlfcn.h"
#include "wrapper/verbose.h"
void
java_lang_System_load(JNIEnv *env, jobject object, va_list args)
{
assert(env && object);
const char *lib = (*env)->GetStringUTFChars(env, va_arg(args, jstring), NULL);
va_end(args);
verbose("%s", lib);
void *handle = bionic_dlopen(lib, RTLD_NOW | RTLD_GLOBAL);
assert(handle);
union {
void *ptr;
void* (*fun)(void*, void*);
} JNI_OnLoad;
if ((JNI_OnLoad.ptr = bionic_dlsym(handle, "JNI_OnLoad"))) {
JavaVM *vm;
(*env)->GetJavaVM(env, &vm);
JNI_OnLoad.fun(vm, NULL);
}
}
jclass
java_lang_Object_getClass(JNIEnv *env, jobject object, va_list args)
{
assert(env && object);
return (*env)->GetObjectClass(env, object);
}
jobject
java_lang_Class_getClassLoader(JNIEnv *env, jobject object, va_list args)
{
assert(env && object);
static jobject sv;
return (sv ? sv : (sv = (*env)->AllocObject(env, (*env)->FindClass(env, "java/lang/ClassLoader"))));
}
jobject
java_lang_ClassLoader_findLibrary(JNIEnv *env, jobject object, va_list args)
{
assert(env && object);
XXX
char lib[255];
snprintf(lib, sizeof(lib), "lib%s.so", (*env)->GetStringUTFChars(env, va_arg(args, jstring), NULL));
va_end(args);
return (*env)->NewStringUTF(env, lib);
}
jobject
java_util_Map_entrySet(JNIEnv *env, jobject object, va_list args)
{
assert(env && object);
static jobject sv;
return (sv ? sv : (sv = (*env)->AllocObject(env, (*env)->FindClass(env, "java/util/Set"))));
}
jobject
java_util_Set_iterator(JNIEnv *env, jobject object, va_list args)
{
assert(env && object);
static jobject sv;
return (sv ? sv : (sv = (*env)->AllocObject(env, (*env)->FindClass(env, "java/util/Iterator"))));
}
jboolean
java_util_Iterator_hasNext(JNIEnv *env, jobject object, va_list args)
{
assert(env && object);
return false;
}
jstring
java_io_File_getPath(JNIEnv *env, jobject object, va_list args)
{
assert(env && object);
FIXME
return (*env)->NewStringUTF(env, "tmp");
}
|