Android-x86
Fork
捐款

  • R/O
  • HTTP
  • SSH
  • HTTPS

dalvik: 提交

dalvik


Commit MetaInfo

修訂068e1b069b87178569f6da761c49e8b5dd9ef987 (tree)
時間2012-12-09 22:46:22
作者Chih-Wei Huang <cwhuang@linu...>
CommiterChih-Wei Huang

Log Message

Update houdini support

The patch requires new houdini for ICS.

Modified from JB patches of Daniel Fages <dfages@android-x86.org>.

Change Summary

差異

--- a/libnativehelper/Register.cpp
+++ b/libnativehelper/Register.cpp
@@ -22,7 +22,7 @@ extern int registerJniHelp(JNIEnv* env);
2222 /*
2323 * Register all methods for system classes.
2424 */
25-extern "C" int jniRegisterSystemMethods(JNIEnv* env) {
25+int jniRegisterSystemMethods(JNIEnv* env) {
2626 // JniHelp depends on core library classes such as java.io.FileDescriptor.
2727 return registerCoreLibrariesJni(env) != -1 && registerJniHelp(env) != -1;
2828 }
--- a/libnativehelper/include/nativehelper/jni.h
+++ b/libnativehelper/include/nativehelper/jni.h
@@ -493,6 +493,11 @@ struct JNINativeInterface {
493493
494494 /* added in JNI 1.6 */
495495 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);
496501 };
497502
498503 /*
@@ -1041,6 +1046,20 @@ struct _JNIEnv {
10411046 /* added in JNI 1.6 */
10421047 jobjectRefType GetObjectRefType(jobject obj)
10431048 { 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+
10441063 #endif /*__cplusplus*/
10451064 };
10461065
--- a/vm/CheckJni.cpp
+++ b/vm/CheckJni.cpp
@@ -1983,6 +1983,25 @@ static jobjectRefType Check_GetObjectRefType(JNIEnv* env, jobject obj) {
19831983 return CHECK_JNI_EXIT("I", baseEnv(env)->GetObjectRefType(env, obj));
19841984 }
19851985
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+
19862005 static jobject Check_NewDirectByteBuffer(JNIEnv* env, void* address, jlong capacity) {
19872006 CHECK_JNI_ENTRY(kFlag_Default, "EpJ", env, address, capacity);
19882007 if (address == NULL || capacity < 0) {
@@ -2321,7 +2340,12 @@ static const struct JNINativeInterface gCheckNativeInterface = {
23212340 Check_GetDirectBufferAddress,
23222341 Check_GetDirectBufferCapacity,
23232342
2324- Check_GetObjectRefType
2343+ Check_GetObjectRefType,
2344+
2345+ Check_DvmDlopen,
2346+ Check_DvmDlsym,
2347+ Check_DvmSetGlobalARM,
2348+ Check_DvmAndroidrt2hdCreateActivity,
23252349 };
23262350
23272351 static const struct JNIInvokeInterface gCheckInvokeInterface = {
--- a/vm/Init.cpp
+++ b/vm/Init.cpp
@@ -42,7 +42,7 @@
4242 /*
4343 * Register VM-agnostic native methods for system classes.
4444 */
45-extern "C" int jniRegisterSystemMethods(JNIEnv* env);
45+extern int jniRegisterSystemMethods(JNIEnv* env);
4646
4747 /* fwd */
4848 static bool registerSystemNatives(JNIEnv* pEnv);
--- a/vm/Jni.cpp
+++ b/vm/Jni.cpp
@@ -763,10 +763,10 @@ static bool dvmRegisterJNIMethod(ClassObject* clazz, const char* methodName,
763763 method->fastJni = fastJni;
764764 dvmUseJNIBridge(method, fnPtr);
765765
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);
770770 return true;
771771 }
772772
@@ -1134,12 +1134,12 @@ void my_dvmPlatformInvoke(void* pEnv, ClassObject* clazz, int argInfo, int argc,
11341134 * Scan the types out of the short signature. Use them to fill out the
11351135 * "types" array. Store the start address of the argument in "values".
11361136 */
1137- /* while ((sigByte = *++signature) != '\0') {
1137+ while ((sigByte = *++signature) != '\0') {
11381138 types[dstArg] = sigByte;
11391139 values[dstArg++] = (void*) argv++;
11401140 if (sigByte == 'D' || sigByte == 'J')
11411141 argv++;
1142- }*/
1142+ }
11431143
11441144 types[dstArg] = 0;
11451145
@@ -2750,6 +2750,27 @@ static jobjectRefType GetObjectRefType(JNIEnv* env, jobject jobj) {
27502750 return dvmGetJNIRefType(ts.self(), jobj);
27512751 }
27522752
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+
27532774 /*
27542775 * Allocate and return a new java.nio.ByteBuffer for this block of memory.
27552776 *
@@ -3317,7 +3338,12 @@ static const struct JNINativeInterface gNativeInterface = {
33173338 GetDirectBufferAddress,
33183339 GetDirectBufferCapacity,
33193340
3320- GetObjectRefType
3341+ GetObjectRefType,
3342+
3343+ DvmDlopen,
3344+ DvmDlsym,
3345+ DvmSetGlobalARM,
3346+ DvmAndroidrt2hdCreateActivity,
33213347 };
33223348
33233349 static const struct JNIInvokeInterface gInvokeInterface = {
--- a/vm/Native.cpp
+++ b/vm/Native.cpp
@@ -32,6 +32,13 @@ int (*h_init)(int (**f)(int, const char *, const char *, ...)) = NULL;
3232 void * (*h_dlopen)(const char *, int) = NULL;
3333 void * (*h_dlsym)(void *, const char *) = NULL;
3434 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+}
3542
3643 static void init_houdini() {
3744 static void *h_handle = NULL;
@@ -57,46 +64,38 @@ static void init_houdini() {
5764 *(void **)(&h_NativeMethodHelper) = dlsym(h_handle, "dvm2hdNativeMethodHelper");
5865 LOGE_IF(!h_NativeMethodHelper, "Unable to find dvm2hdNativeMethodHelper() function");
5966
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;
6171
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);
6474 }
6575
6676 void * (*h_dvmHoudiniDlopen)(const char *, int) = NULL;
6777 void (*h_dvmHoudiniPlatformInvoke)(void*, ClassObject*, int, int, const u4*, const char*, void*, JValue *);
6878
69-int jniRegisterSystemMethods(void *p)
70-{
71- LOGE("fake jniRegisterSystemMethods()");
72- return 1;
73-}
74-
7579 static void init_dvm_houdini() {
7680 static void *h_handle = NULL;
7781
7882 if (h_handle)
7983 return;
8084
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-
8685 h_handle = dlopen("libdvm_houdini.so", RTLD_LAZY);
8786 if (!h_handle) {
8887 LOGE("Unable to open libdvm_houdini lib: %s\n", dlerror());
8988 return;
9089 }
9190
92- *(void **)(&h_dvmHoudiniDlopen) = dlsym(h_handle, "dvmHoudiniDlopen");
91+ *(void **)(&h_dvmHoudiniDlopen) = dlsym(h_handle, "_Z16dvmHoudiniDlopenPKci");
9392 LOGE_IF(!h_dvmHoudiniDlopen, "Unable to find dvmHoudiniDlopen() function");
9493
95- *(void **)(&h_dvmHoudiniPlatformInvoke) = dlsym(h_handle, "dvmHoudiniPlatformInvoke");
94+ *(void **)(&h_dvmHoudiniPlatformInvoke) = dlsym(h_handle, "_Z24dvmHoudiniPlatformInvokePvP11ClassObjectiiPKjPKcS_P6JValue");
9695 LOGE_IF(!h_dvmHoudiniPlatformInvoke, "Unable to find dvmHoudiniPlatformInvoke() function");
9796 }
9897
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) {
10099 void *r;
101100
102101 if (p_is_arm)
@@ -113,7 +112,7 @@ static void *my_dlopen(const char *filename, int flag, int *p_is_arm) {
113112 }
114113
115114 if (!r) {
116- LOGE("my_dlopen: unable to open %s\n", filename);
115+ LOGE("dvm_dlopen: unable to open %s\n", filename);
117116 return r;
118117 }
119118
@@ -123,18 +122,27 @@ static void *my_dlopen(const char *filename, int flag, int *p_is_arm) {
123122 return r;
124123 }
125124
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) {
127126 void *r;
128127
129- init_houdini();
130-
131128 if (is_arm) {
129+ init_houdini();
130+
132131 return (h_dlsym) ? (*h_dlsym)(handle, symbol) : NULL;
133132 } else {
134133 return dlsym(handle, symbol);
135134 }
136135 }
137136
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+
138146 static void freeSharedLibEntry(void* ptr);
139147 static void* lookupSharedLibMethod(const Method* method);
140148
@@ -493,7 +501,7 @@ bool dvmLoadNativeCode(const char* pathName, Object* classLoader,
493501 */
494502 Thread* self = dvmThreadSelf();
495503 ThreadStatus oldStatus = dvmChangeStatus(self, THREAD_VMWAIT);
496- handle = my_dlopen(pathName, RTLD_LAZY, &is_arm);
504+ handle = dvm_dlopen(pathName, RTLD_LAZY, &is_arm);
497505 dvmChangeStatus(self, oldStatus);
498506
499507 if (handle == NULL) {
@@ -528,7 +536,7 @@ bool dvmLoadNativeCode(const char* pathName, Object* classLoader,
528536 void* vonLoad;
529537 int version;
530538
531- vonLoad = my_dlsym(handle, "JNI_OnLoad", is_arm);
539+ vonLoad = dvm_dlsym(handle, "JNI_OnLoad", is_arm);
532540 if (vonLoad == NULL) {
533541 LOGD("No JNI_OnLoad found in %s %p, skipping init",
534542 pathName, classLoader);
@@ -557,7 +565,7 @@ bool dvmLoadNativeCode(const char* pathName, Object* classLoader,
557565 LOGE("Version returned : %d", version);
558566 }
559567 } else {
560- version = (*func)(gDvmJni.jniVm, NULL);
568+ version = (*func)(gDvmJni.jniVm, NULL);
561569 }
562570 dvmChangeStatus(self, oldStatus);
563571 self->classLoaderOverride = prevOverride;
@@ -841,7 +849,7 @@ static int findMethodInLib(void* vlib, void* vmethod)
841849 goto bail;
842850
843851 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);
845853 if (func == NULL) {
846854 mangleSig =
847855 createMangledSignature(&meth->prototype);
@@ -855,7 +863,7 @@ static int findMethodInLib(void* vlib, void* vmethod)
855863 sprintf(mangleCMSig, "%s__%s", mangleCM, mangleSig);
856864
857865 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);
859867 if (func != NULL) {
860868 LOGV("Found '%s' with dlsym - func=%p", mangleCMSig, func);
861869 }
--- a/vm/Native.h
+++ b/vm/Native.h
@@ -64,6 +64,9 @@ u4 dvmPlatformInvokeHints(const DexProto* proto);
6464 char* dvmCreateSystemLibraryName(char* libName);
6565 bool dvmLoadNativeCode(const char* fileName, Object* classLoader,
6666 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);
6770
6871
6972 /*
Show on old repository browser