From 7f4c0b3118bd1b2d25a528e06c021d11c43e2cf7 Mon Sep 17 00:00:00 2001 From: Joel Dice Date: Fri, 22 Aug 2014 07:05:58 -0600 Subject: [PATCH] fix SSL stack and Android JAR resource loading --- README.md | 5 +++++ classpath/java/lang/Class.java | 4 +++- makefile | 27 +++++++++++++++++++++++++-- src/android/stubs.cpp | 7 +++++++ src/classpath-android.cpp | 5 +++++ src/machine.cpp | 2 -- 6 files changed, 45 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index 849fdf71cb..e314b6fb21 100644 --- a/README.md +++ b/README.md @@ -396,6 +396,11 @@ the following, starting from the Avian directory: (cd external/zlib && \ git checkout 15b6223aa57a347ce113729253802cb2fdeb4ad0) + git clone https://android.googlesource.com/platform/external/conscrypt \ + external/conscrypt + (cd external/conscrypt && \ + git checkout 076138ff29d805ec5a32d6ad96a18ef08c7f1b11) + git clone git://git.openssl.org/openssl.git openssl-upstream (cd openssl-upstream && git checkout OpenSSL_1_0_1h) diff --git a/classpath/java/lang/Class.java b/classpath/java/lang/Class.java index 93ac0d77f5..3aa35d06a8 100644 --- a/classpath/java/lang/Class.java +++ b/classpath/java/lang/Class.java @@ -529,7 +529,9 @@ public final class Class } public URL getResource(String path) { - if (! path.startsWith("/")) { + if (path.startsWith("/")) { + path = path.substring(1); + } else { String name = Classes.makeString (vmClass.name, 0, vmClass.name.length - 1); int index = name.lastIndexOf('/'); diff --git a/makefile b/makefile index 45f70d2875..4e3a5c5884 100755 --- a/makefile +++ b/makefile @@ -226,6 +226,7 @@ ifneq ($(android),) -I$(android)/external/icu4c/common \ -I$(android)/external/expat \ -I$(android)/external/openssl/include \ + -I$(android)/external/openssl \ -I$(android)/libcore/include \ -I$(build)/android-src/external/fdlibm \ -I$(build)/android-src \ @@ -236,6 +237,7 @@ ifneq ($(android),) -D__DARWIN_UNIX03=1 \ -D__PROVIDE_FIXMES \ -DHAVE_OFF64_T \ + -DSTATIC_LIB \ -g3 \ -Werror @@ -251,6 +253,9 @@ ifneq ($(android),) libnativehelper-cpps := $(libnativehelper-native)/JniConstants.cpp \ $(libnativehelper-native)/toStringArray.cpp + crypto-native := $(android)/external/conscrypt/src/main/native + crypto-cpps := $(crypto-native)/org_conscrypt_NativeCrypto.cpp + ifeq ($(platform),windows) android-cflags += -D__STDC_CONSTANT_MACROS -DHAVE_WIN32_FILEMAP blacklist = $(luni-native)/java_io_Console.cpp \ @@ -274,8 +279,8 @@ ifneq ($(android),) $(icu-libs) \ $(android)/external/fdlibm/libfdm.a \ $(android)/external/expat/.libs/libexpat.a \ - $(android)/openssl-upstream/libcrypto.a \ $(android)/openssl-upstream/libssl.a \ + $(android)/openssl-upstream/libcrypto.a \ $(platform-lflags) \ -lstdc++ @@ -285,6 +290,7 @@ ifneq ($(android),) classpath-objects = \ $(call cpp-objects,$(luni-cpps),$(luni-native),$(build)) \ + $(call cpp-objects,$(crypto-cpps),$(crypto-native),$(build)) \ $(call cpp-objects,$(libnativehelper-cpps),$(libnativehelper-native),$(build)) \ $(call cc-objects,$(libziparchive-ccs),$(libziparchive-native),$(build)) \ $(call cpp-objects,$(libutils-cpps),$(libutils-native),$(build)) @@ -299,6 +305,12 @@ ifneq ($(android),) luni-nonjavas := $(shell find $(luni-java) -not -type d -not -name '*.java') luni-copied-nonjavas = $(call noop-files,$(luni-nonjavas),$(luni-java),) + crypto-java = $(android)/external/conscrypt/src/main/java + crypto-javas := $(shell find $(crypto-java) -name '*.java') + + crypto-platform-java = $(android)/external/conscrypt/src/platform/java + crypto-platform-javas := $(shell find $(crypto-platform-java) -name '*.java') + dalvik-java = $(android)/libcore/dalvik/src/main/java dalvik-javas := \ $(dalvik-java)/dalvik/system/DalvikLogHandler.java \ @@ -323,6 +335,8 @@ ifneq ($(android),) xml-javas := $(shell find $(xml-java) -name '*.java') android-classes = \ $(call java-classes,$(luni-javas),$(luni-java),$(build)/android) \ + $(call java-classes,$(crypto-javas),$(crypto-java),$(build)/android) \ + $(call java-classes,$(crypto-platform-javas),$(crypto-platform-java),$(build)/android) \ $(call java-classes,$(dalvik-javas),$(dalvik-java),$(build)/android) \ $(call java-classes,$(libart-javas),$(libart-java),$(build)/android) \ $(call java-classes,$(xml-javas),$(xml-java),$(build)/android) @@ -1624,6 +1638,9 @@ $(build)/android-src/%.cpp: $(luni-native)/%.cpp $(build)/android-src/%.cpp: $(libnativehelper-native)/%.cpp cp $(<) $(@) +$(build)/android-src/%.cpp: $(crypto-native)/%.cpp + cp $(<) $(@) + $(build)/android-src/%.cpp: $(libziparchive-native)/%.cc cp $(<) $(@) @@ -1637,7 +1654,7 @@ $(build)/%.o: $(build)/android-src/%.cpp $(build)/android.dep $$($(windows-path) $(<)) $(call output,$(@)) $(build)/android.dep: $(luni-javas) $(dalvik-javas) $(libart-javas) \ - $(xml-javas) $(luni-nonjavas) + $(xml-javas) $(luni-nonjavas) $(crypto-javas) $(crypto-platform-javas) @echo "compiling luni classes" @mkdir -p $(classpath-build) @mkdir -p $(build)/android @@ -1653,6 +1670,12 @@ $(build)/android.dep: $(luni-javas) $(dalvik-javas) $(libart-javas) \ (cd $(libart-java) && \ jar c $(call noop-files,$(libart-javas),$(libart-java),.)) \ | (cd $(build)/android-src && jar x) + (cd $(crypto-java) && \ + jar c $(call noop-files,$(crypto-javas),$(crypto-java),.)) \ + | (cd $(build)/android-src && jar x) + (cd $(crypto-platform-java) && \ + jar c $(call noop-files,$(crypto-platform-javas),$(crypto-platform-java),.)) \ + | (cd $(build)/android-src && jar x) (cd $(classpath-src) && \ jar c $(call noop-files,$(classpath-sources),$(classpath-src),.)) \ | (cd $(build)/android-src && jar x) diff --git a/src/android/stubs.cpp b/src/android/stubs.cpp index 7fe9362a3d..0c1295d464 100644 --- a/src/android/stubs.cpp +++ b/src/android/stubs.cpp @@ -15,3 +15,10 @@ void JniConstants::init(_JNIEnv*) { // ignore } + +struct _JavaVM; + +int libconscrypt_JNI_OnLoad(_JavaVM*, void*) +{ + return 0; +} diff --git a/src/classpath-android.cpp b/src/classpath-android.cpp index 7994c51b48..69d5ab81cf 100644 --- a/src/classpath-android.cpp +++ b/src/classpath-android.cpp @@ -9,6 +9,7 @@ details. */ struct JavaVM; +struct _JavaVM; struct _JNIEnv; struct JniConstants { @@ -17,6 +18,8 @@ struct JniConstants { extern "C" int JNI_OnLoad(JavaVM*, void*); +int libconscrypt_JNI_OnLoad(_JavaVM*, void*); + #define _POSIX_C_SOURCE 200112L #undef _GNU_SOURCE #include "avian/machine.h" @@ -393,6 +396,8 @@ class MyClasspath : public Classpath { JNI_OnLoad(reinterpret_cast< ::JavaVM*>(t->m), 0); + libconscrypt_JNI_OnLoad(reinterpret_cast< ::_JavaVM*>(t->m), 0); + mayInitClasses_ = true; } diff --git a/src/machine.cpp b/src/machine.cpp index 8647ad0ff8..ecc30b3361 100644 --- a/src/machine.cpp +++ b/src/machine.cpp @@ -5665,8 +5665,6 @@ void runFinalizeThread(Thread* t) GcCleaner* cleanList = 0; PROTECT(t, cleanList); - fprintf(stderr, "run finalize thread!\n"); - while (true) { { ACQUIRE(t, t->m->stateLock);