修訂 | 068e1b069b87178569f6da761c49e8b5dd9ef987 (tree) |
---|---|
時間 | 2012-12-09 22:46:22 |
作者 | Chih-Wei Huang <cwhuang@linu...> |
Commiter | Chih-Wei Huang |
Update houdini support
The patch requires new houdini for ICS.
Modified from JB patches of Daniel Fages <dfages@android-x86.org>.
@@ -22,7 +22,7 @@ extern int registerJniHelp(JNIEnv* env); | ||
22 | 22 | /* |
23 | 23 | * Register all methods for system classes. |
24 | 24 | */ |
25 | -extern "C" int jniRegisterSystemMethods(JNIEnv* env) { | |
25 | +int jniRegisterSystemMethods(JNIEnv* env) { | |
26 | 26 | // JniHelp depends on core library classes such as java.io.FileDescriptor. |
27 | 27 | return registerCoreLibrariesJni(env) != -1 && registerJniHelp(env) != -1; |
28 | 28 | } |
@@ -493,6 +493,11 @@ struct JNINativeInterface { | ||
493 | 493 | |
494 | 494 | /* added in JNI 1.6 */ |
495 | 495 | jobjectRefType (*GetObjectRefType)(JNIEnv*, jobject); |
496 | + | |
497 | + void* (*DvmDlopen)(JNIEnv *, const char *, int); | |
498 | + void* (*DvmDlsym)(JNIEnv *, void *, const char *); | |
499 | + void (*DvmSetGlobalARM)(int); | |
500 | + void (*DvmAndroidrt2hdCreateActivity)(void *fn, void *code, void *native, void *rawSavedState, int rawSavedSize); | |
496 | 501 | }; |
497 | 502 | |
498 | 503 | /* |
@@ -1041,6 +1046,20 @@ struct _JNIEnv { | ||
1041 | 1046 | /* added in JNI 1.6 */ |
1042 | 1047 | jobjectRefType GetObjectRefType(jobject obj) |
1043 | 1048 | { return functions->GetObjectRefType(this, obj); } |
1049 | + | |
1050 | + | |
1051 | + void* DvmDlopen(const char * filename, int flags) | |
1052 | + { return functions->DvmDlopen(this, filename, flags); } | |
1053 | + | |
1054 | + void* DvmDlsym(void *handle, const char *func) | |
1055 | + { return functions->DvmDlsym(this, handle, func); } | |
1056 | + | |
1057 | + void DvmSetGlobalARM(int i) | |
1058 | + { return functions->DvmSetGlobalARM(i); } | |
1059 | + | |
1060 | + void DvmAndroidrt2hdCreateActivity(void *fn, void *code, void *native, void *rawSavedState, int rawSavedSize) | |
1061 | + { return functions->DvmAndroidrt2hdCreateActivity(fn, code, native, rawSavedState, rawSavedSize); } | |
1062 | + | |
1044 | 1063 | #endif /*__cplusplus*/ |
1045 | 1064 | }; |
1046 | 1065 |
@@ -1983,6 +1983,25 @@ static jobjectRefType Check_GetObjectRefType(JNIEnv* env, jobject obj) { | ||
1983 | 1983 | return CHECK_JNI_EXIT("I", baseEnv(env)->GetObjectRefType(env, obj)); |
1984 | 1984 | } |
1985 | 1985 | |
1986 | +static void* Check_DvmDlopen(JNIEnv *env, const char * filename, int flags) { | |
1987 | + //return baseEnv(env)->DvmDlopen(env, filename, flags); | |
1988 | + return NULL; | |
1989 | +} | |
1990 | + | |
1991 | +static void* Check_DvmDlsym(JNIEnv *env, void *handle, const char * func) { | |
1992 | + //return baseEnv(env)->DvmDlsym(handle, func, 1); | |
1993 | + return NULL; | |
1994 | +} | |
1995 | + | |
1996 | +static void Check_DvmSetGlobalARM(int i) { | |
1997 | + //return baseEnv(env)->DvmSetGlobalARM(i); | |
1998 | +} | |
1999 | + | |
2000 | +static void Check_DvmAndroidrt2hdCreateActivity(void *fn, void *code, void *native, void *rawSavedState, int rawSavedSize) { | |
2001 | + //return baseEnv(env)->DvmAndroidrt2hdCreateActivity(fn, code, native, rawSavedState, rawSavedSize); | |
2002 | +} | |
2003 | + | |
2004 | + | |
1986 | 2005 | static jobject Check_NewDirectByteBuffer(JNIEnv* env, void* address, jlong capacity) { |
1987 | 2006 | CHECK_JNI_ENTRY(kFlag_Default, "EpJ", env, address, capacity); |
1988 | 2007 | if (address == NULL || capacity < 0) { |
@@ -2321,7 +2340,12 @@ static const struct JNINativeInterface gCheckNativeInterface = { | ||
2321 | 2340 | Check_GetDirectBufferAddress, |
2322 | 2341 | Check_GetDirectBufferCapacity, |
2323 | 2342 | |
2324 | - Check_GetObjectRefType | |
2343 | + Check_GetObjectRefType, | |
2344 | + | |
2345 | + Check_DvmDlopen, | |
2346 | + Check_DvmDlsym, | |
2347 | + Check_DvmSetGlobalARM, | |
2348 | + Check_DvmAndroidrt2hdCreateActivity, | |
2325 | 2349 | }; |
2326 | 2350 | |
2327 | 2351 | static const struct JNIInvokeInterface gCheckInvokeInterface = { |
@@ -42,7 +42,7 @@ | ||
42 | 42 | /* |
43 | 43 | * Register VM-agnostic native methods for system classes. |
44 | 44 | */ |
45 | -extern "C" int jniRegisterSystemMethods(JNIEnv* env); | |
45 | +extern int jniRegisterSystemMethods(JNIEnv* env); | |
46 | 46 | |
47 | 47 | /* fwd */ |
48 | 48 | static bool registerSystemNatives(JNIEnv* pEnv); |
@@ -763,10 +763,10 @@ static bool dvmRegisterJNIMethod(ClassObject* clazz, const char* methodName, | ||
763 | 763 | method->fastJni = fastJni; |
764 | 764 | dvmUseJNIBridge(method, fnPtr); |
765 | 765 | |
766 | - if (global_is_arm) | |
767 | - method->is_arm = 1; | |
768 | - | |
769 | - LOGV("JNI-registered %s.%s:%s", clazz->descriptor, methodName, signature); | |
766 | + if (global_is_arm) { | |
767 | + method->is_arm = 1; | |
768 | + } | |
769 | + LOGV("JNI-registered %s.%s:%s with arm=%d", clazz->descriptor, methodName, signature, global_is_arm); | |
770 | 770 | return true; |
771 | 771 | } |
772 | 772 |
@@ -1134,12 +1134,12 @@ void my_dvmPlatformInvoke(void* pEnv, ClassObject* clazz, int argInfo, int argc, | ||
1134 | 1134 | * Scan the types out of the short signature. Use them to fill out the |
1135 | 1135 | * "types" array. Store the start address of the argument in "values". |
1136 | 1136 | */ |
1137 | - /* while ((sigByte = *++signature) != '\0') { | |
1137 | + while ((sigByte = *++signature) != '\0') { | |
1138 | 1138 | types[dstArg] = sigByte; |
1139 | 1139 | values[dstArg++] = (void*) argv++; |
1140 | 1140 | if (sigByte == 'D' || sigByte == 'J') |
1141 | 1141 | argv++; |
1142 | - }*/ | |
1142 | + } | |
1143 | 1143 | |
1144 | 1144 | types[dstArg] = 0; |
1145 | 1145 |
@@ -2750,6 +2750,27 @@ static jobjectRefType GetObjectRefType(JNIEnv* env, jobject jobj) { | ||
2750 | 2750 | return dvmGetJNIRefType(ts.self(), jobj); |
2751 | 2751 | } |
2752 | 2752 | |
2753 | +static void* DvmDlopen(JNIEnv *env, const char * filename, int flags) { | |
2754 | + ScopedJniThreadState ts(env); | |
2755 | + | |
2756 | + return dvm_dlopen(filename, flags, NULL); | |
2757 | +} | |
2758 | + | |
2759 | +static void* DvmDlsym(JNIEnv *env, void *handle, const char * func) { | |
2760 | + ScopedJniThreadState ts(env); | |
2761 | + | |
2762 | + return dvm_dlsym(handle, func, 1); | |
2763 | +} | |
2764 | + | |
2765 | +static void DvmSetGlobalARM(int i) { | |
2766 | + LOGE("Setting GLobal ARM to %d", i); | |
2767 | + global_is_arm = i; | |
2768 | +} | |
2769 | + | |
2770 | +static void DvmAndroidrt2hdCreateActivity(void *fn, void *code, void *native, void *rawSavedState, int rawSavedSize) { | |
2771 | + dvm_androidrt2hdCreateActivity(fn, code, native, rawSavedState, rawSavedSize); | |
2772 | +} | |
2773 | + | |
2753 | 2774 | /* |
2754 | 2775 | * Allocate and return a new java.nio.ByteBuffer for this block of memory. |
2755 | 2776 | * |
@@ -3317,7 +3338,12 @@ static const struct JNINativeInterface gNativeInterface = { | ||
3317 | 3338 | GetDirectBufferAddress, |
3318 | 3339 | GetDirectBufferCapacity, |
3319 | 3340 | |
3320 | - GetObjectRefType | |
3341 | + GetObjectRefType, | |
3342 | + | |
3343 | + DvmDlopen, | |
3344 | + DvmDlsym, | |
3345 | + DvmSetGlobalARM, | |
3346 | + DvmAndroidrt2hdCreateActivity, | |
3321 | 3347 | }; |
3322 | 3348 | |
3323 | 3349 | static const struct JNIInvokeInterface gInvokeInterface = { |
@@ -32,6 +32,13 @@ int (*h_init)(int (**f)(int, const char *, const char *, ...)) = NULL; | ||
32 | 32 | void * (*h_dlopen)(const char *, int) = NULL; |
33 | 33 | void * (*h_dlsym)(void *, const char *) = NULL; |
34 | 34 | void (*h_NativeMethodHelper)(int, void *, int, JValue *, int, unsigned char *, void *) = NULL; |
35 | +void (*h_androidrt2hdCreateActivity)(void *fn, void *code, void *native, void *rawSavedState, int rawSavedSize) = NULL; | |
36 | + | |
37 | +int my_android_log_print(int prio, const char *tag, const char *fmt, ...) | |
38 | +{ | |
39 | + LOGE("my_android_log_print() called"); | |
40 | + return 0; | |
41 | +} | |
35 | 42 | |
36 | 43 | static void init_houdini() { |
37 | 44 | static void *h_handle = NULL; |
@@ -57,46 +64,38 @@ static void init_houdini() { | ||
57 | 64 | *(void **)(&h_NativeMethodHelper) = dlsym(h_handle, "dvm2hdNativeMethodHelper"); |
58 | 65 | LOGE_IF(!h_NativeMethodHelper, "Unable to find dvm2hdNativeMethodHelper() function"); |
59 | 66 | |
60 | - int (*my_f)(int, const char *, const char *, ...) = __android_log_print; | |
67 | + *(void **)(&h_androidrt2hdCreateActivity) = dlsym(h_handle, "androidrt2hdCreateActivity"); | |
68 | + LOGE_IF(!h_androidrt2hdCreateActivity, "Unable to find androidrt2hdCreateActivity() function"); | |
69 | + | |
70 | + //int (*my_f)(int, const char *, const char *, ...) = __android_log_print; | |
61 | 71 | |
62 | - int r_init = (*h_init)(&my_f); | |
63 | - LOGE("dvm2hdInit() returned %d\n", r_init); | |
72 | + //int r_init = (*h_init)(&my_f); | |
73 | + //LOGE("dvm2hdInit() returned %d\n", r_init); | |
64 | 74 | } |
65 | 75 | |
66 | 76 | void * (*h_dvmHoudiniDlopen)(const char *, int) = NULL; |
67 | 77 | void (*h_dvmHoudiniPlatformInvoke)(void*, ClassObject*, int, int, const u4*, const char*, void*, JValue *); |
68 | 78 | |
69 | -int jniRegisterSystemMethods(void *p) | |
70 | -{ | |
71 | - LOGE("fake jniRegisterSystemMethods()"); | |
72 | - return 1; | |
73 | -} | |
74 | - | |
75 | 79 | static void init_dvm_houdini() { |
76 | 80 | static void *h_handle = NULL; |
77 | 81 | |
78 | 82 | if (h_handle) |
79 | 83 | return; |
80 | 84 | |
81 | -#if 0 | |
82 | - if (!dlopen("libnativehelper_GBfake.so", RTLD_LAZY | RTLD_GLOBAL)) | |
83 | - LOGE("Unable to open libnativehelper_GBfake.so"); | |
84 | -#endif //0 | |
85 | - | |
86 | 85 | h_handle = dlopen("libdvm_houdini.so", RTLD_LAZY); |
87 | 86 | if (!h_handle) { |
88 | 87 | LOGE("Unable to open libdvm_houdini lib: %s\n", dlerror()); |
89 | 88 | return; |
90 | 89 | } |
91 | 90 | |
92 | - *(void **)(&h_dvmHoudiniDlopen) = dlsym(h_handle, "dvmHoudiniDlopen"); | |
91 | + *(void **)(&h_dvmHoudiniDlopen) = dlsym(h_handle, "_Z16dvmHoudiniDlopenPKci"); | |
93 | 92 | LOGE_IF(!h_dvmHoudiniDlopen, "Unable to find dvmHoudiniDlopen() function"); |
94 | 93 | |
95 | - *(void **)(&h_dvmHoudiniPlatformInvoke) = dlsym(h_handle, "dvmHoudiniPlatformInvoke"); | |
94 | + *(void **)(&h_dvmHoudiniPlatformInvoke) = dlsym(h_handle, "_Z24dvmHoudiniPlatformInvokePvP11ClassObjectiiPKjPKcS_P6JValue"); | |
96 | 95 | LOGE_IF(!h_dvmHoudiniPlatformInvoke, "Unable to find dvmHoudiniPlatformInvoke() function"); |
97 | 96 | } |
98 | 97 | |
99 | -static void *my_dlopen(const char *filename, int flag, int *p_is_arm) { | |
98 | +void *dvm_dlopen(const char *filename, int flag, int *p_is_arm) { | |
100 | 99 | void *r; |
101 | 100 | |
102 | 101 | if (p_is_arm) |
@@ -113,7 +112,7 @@ static void *my_dlopen(const char *filename, int flag, int *p_is_arm) { | ||
113 | 112 | } |
114 | 113 | |
115 | 114 | if (!r) { |
116 | - LOGE("my_dlopen: unable to open %s\n", filename); | |
115 | + LOGE("dvm_dlopen: unable to open %s\n", filename); | |
117 | 116 | return r; |
118 | 117 | } |
119 | 118 |
@@ -123,18 +122,27 @@ static void *my_dlopen(const char *filename, int flag, int *p_is_arm) { | ||
123 | 122 | return r; |
124 | 123 | } |
125 | 124 | |
126 | -static void *my_dlsym(void *handle, const char *symbol, int is_arm) { | |
125 | +void *dvm_dlsym(void *handle, const char *symbol, int is_arm) { | |
127 | 126 | void *r; |
128 | 127 | |
129 | - init_houdini(); | |
130 | - | |
131 | 128 | if (is_arm) { |
129 | + init_houdini(); | |
130 | + | |
132 | 131 | return (h_dlsym) ? (*h_dlsym)(handle, symbol) : NULL; |
133 | 132 | } else { |
134 | 133 | return dlsym(handle, symbol); |
135 | 134 | } |
136 | 135 | } |
137 | 136 | |
137 | +void dvm_androidrt2hdCreateActivity(void *fn, void *code, void *native, void *rawSavedState, int rawSavedSize) | |
138 | +{ | |
139 | + if (h_androidrt2hdCreateActivity) { | |
140 | + h_androidrt2hdCreateActivity(fn, code, native, rawSavedState, rawSavedSize); | |
141 | + } | |
142 | +} | |
143 | + | |
144 | + | |
145 | + | |
138 | 146 | static void freeSharedLibEntry(void* ptr); |
139 | 147 | static void* lookupSharedLibMethod(const Method* method); |
140 | 148 |
@@ -493,7 +501,7 @@ bool dvmLoadNativeCode(const char* pathName, Object* classLoader, | ||
493 | 501 | */ |
494 | 502 | Thread* self = dvmThreadSelf(); |
495 | 503 | ThreadStatus oldStatus = dvmChangeStatus(self, THREAD_VMWAIT); |
496 | - handle = my_dlopen(pathName, RTLD_LAZY, &is_arm); | |
504 | + handle = dvm_dlopen(pathName, RTLD_LAZY, &is_arm); | |
497 | 505 | dvmChangeStatus(self, oldStatus); |
498 | 506 | |
499 | 507 | if (handle == NULL) { |
@@ -528,7 +536,7 @@ bool dvmLoadNativeCode(const char* pathName, Object* classLoader, | ||
528 | 536 | void* vonLoad; |
529 | 537 | int version; |
530 | 538 | |
531 | - vonLoad = my_dlsym(handle, "JNI_OnLoad", is_arm); | |
539 | + vonLoad = dvm_dlsym(handle, "JNI_OnLoad", is_arm); | |
532 | 540 | if (vonLoad == NULL) { |
533 | 541 | LOGD("No JNI_OnLoad found in %s %p, skipping init", |
534 | 542 | pathName, classLoader); |
@@ -557,7 +565,7 @@ bool dvmLoadNativeCode(const char* pathName, Object* classLoader, | ||
557 | 565 | LOGE("Version returned : %d", version); |
558 | 566 | } |
559 | 567 | } else { |
560 | - version = (*func)(gDvmJni.jniVm, NULL); | |
568 | + version = (*func)(gDvmJni.jniVm, NULL); | |
561 | 569 | } |
562 | 570 | dvmChangeStatus(self, oldStatus); |
563 | 571 | self->classLoaderOverride = prevOverride; |
@@ -841,7 +849,7 @@ static int findMethodInLib(void* vlib, void* vmethod) | ||
841 | 849 | goto bail; |
842 | 850 | |
843 | 851 | LOGV("+++ calling dlsym(%s)", mangleCM); |
844 | - func = my_dlsym(pLib->handle, mangleCM, pLib->is_arm); | |
852 | + func = dvm_dlsym(pLib->handle, mangleCM, pLib->is_arm); | |
845 | 853 | if (func == NULL) { |
846 | 854 | mangleSig = |
847 | 855 | createMangledSignature(&meth->prototype); |
@@ -855,7 +863,7 @@ static int findMethodInLib(void* vlib, void* vmethod) | ||
855 | 863 | sprintf(mangleCMSig, "%s__%s", mangleCM, mangleSig); |
856 | 864 | |
857 | 865 | LOGV("+++ calling dlsym(%s)", mangleCMSig); |
858 | - func = my_dlsym(pLib->handle, mangleCMSig, pLib->is_arm); | |
866 | + func = dvm_dlsym(pLib->handle, mangleCMSig, pLib->is_arm); | |
859 | 867 | if (func != NULL) { |
860 | 868 | LOGV("Found '%s' with dlsym - func=%p", mangleCMSig, func); |
861 | 869 | } |
@@ -64,6 +64,9 @@ u4 dvmPlatformInvokeHints(const DexProto* proto); | ||
64 | 64 | char* dvmCreateSystemLibraryName(char* libName); |
65 | 65 | bool dvmLoadNativeCode(const char* fileName, Object* classLoader, |
66 | 66 | char** detail); |
67 | +void *dvm_dlopen(const char *filename, int flag, int *p_is_arm); | |
68 | +void *dvm_dlsym(void *handle, const char *symbol, int is_arm); | |
69 | +void dvm_androidrt2hdCreateActivity(void *fn, void *code, void *native, void *rawSavedState, int rawSavedSize); | |
67 | 70 | |
68 | 71 | |
69 | 72 | /* |