Build SGX against deterministic fork of OpenJDK8 (#16)

* Update SGX build to use deterministic OpenJDK repository.
* Remove unused imports.
* Update Kotlin dependencies.
* Update Avian so that it compiles against our OpenJDK repo.
Also include sunec.jar in the Avian binary. because the Enclavlet needs it.
* Embed jsse.jar within Avian to enable X.509 support.
This commit is contained in:
Chris Rankin 2017-07-19 13:29:47 +01:00 committed by GitHub
parent 9411c223af
commit 4b3a804990
29 changed files with 75 additions and 1228 deletions

View File

@ -2,6 +2,9 @@ MAKEFILE_DIR:=$(shell dirname $(realpath $(lastword $(MAKEFILE_LIST))))
ROOT=$(MAKEFILE_DIR)/dependencies/root ROOT=$(MAKEFILE_DIR)/dependencies/root
SHELL=/bin/bash SHELL=/bin/bash
# JAVA_HOME=$(ROOT)/usr/lib/jvm/java-8-openjdk-amd64 # JAVA_HOME=$(ROOT)/usr/lib/jvm/java-8-openjdk-amd64
# JAVA_HOME=$(ROOT)/usr/lib/jvm/java-openjdk
JDK_IMAGE=$(PWD)/jdk8u/build/linux-x86_64-normal-server-release/images/j2re-image
.PHONY: all .PHONY: all
all: jvm-enclave/standalone/build/standalone_sgx_verify all: jvm-enclave/standalone/build/standalone_sgx_verify
@ -14,8 +17,8 @@ jvm-enclave/standalone/build/standalone_sgx_verify: avian linux-sgx/build/linux/
AVIAN_EXTRA_CFLAGS="-I$(ROOT)/usr/include -I$(ROOT)/usr/include/x86_64-linux-gnu" AVIAN_EXTRA_CFLAGS="-I$(ROOT)/usr/include -I$(ROOT)/usr/include/x86_64-linux-gnu"
AVIAN_EXTRA_LDFLAGS="-L$(ROOT)/usr/lib -L$(ROOT)/usr/lib/x86_64-linux-gnu -ldl -lpthread -lz" AVIAN_EXTRA_LDFLAGS="-L$(ROOT)/usr/lib -L$(ROOT)/usr/lib/x86_64-linux-gnu -ldl -lpthread -lz"
.PHONY: avian .PHONY: avian
avian: | jdk8u/hotspot avian: | $(JDK_IMAGE)
PATH=$(ROOT)/usr/bin:$(PATH) $(MAKE) -C avian build-lflags=$(AVIAN_EXTRA_LDFLAGS) extra-lflags=$(AVIAN_EXTRA_LDFLAGS) extra-build-cflags+=$(AVIAN_EXTRA_CFLAGS) extra-cflags+=$(AVIAN_EXTRA_CFLAGS) mode=debug openjdk=$(JAVA_HOME) openjdk-src=../jdk8u/jdk/src system=sgx PATH=$(ROOT)/usr/bin:$(PATH) $(MAKE) -C avian build-lflags=$(AVIAN_EXTRA_LDFLAGS) extra-lflags=$(AVIAN_EXTRA_LDFLAGS) extra-build-cflags+=$(AVIAN_EXTRA_CFLAGS) extra-cflags+=$(AVIAN_EXTRA_CFLAGS) mode=debug openjdk=$(JAVA_HOME) openjdk-src=$(PWD)/jdk8u/jdk/src openjdk-image=$(JDK_IMAGE) system=sgx
# The SGX SDK # The SGX SDK
LINUX_SGX_SOURCES=$(shell find linux-sgx \( -name '*.c' -o -name '*.cpp' -o -name '*.h' -o -name '*.edl' \) ! \( -name '*_u.?' -o -name '*_t.?' -o -name '*.pb.h' -o -path 'linux-sgx/sdk/cpprt/linux/libunwind/*' -o -path 'linux-sgx/external/rdrand/src/config.h' \)) # Poor man's up-to-date check (they don't have one in the SDK??) LINUX_SGX_SOURCES=$(shell find linux-sgx \( -name '*.c' -o -name '*.cpp' -o -name '*.h' -o -name '*.edl' \) ! \( -name '*_u.?' -o -name '*_t.?' -o -name '*.pb.h' -o -path 'linux-sgx/sdk/cpprt/linux/libunwind/*' -o -path 'linux-sgx/external/rdrand/src/config.h' \)) # Poor man's up-to-date check (they don't have one in the SDK??)
@ -23,10 +26,10 @@ linux-sgx/build/linux/aesm_service: $(LINUX_SGX_SOURCES) linux-sgx/external/ippc
LD_LIBRARY_PATH=$(ROOT)/usr/lib/x86_64-linux-gnu:$(ROOT)/lib/x86_64-linux-gnu LIBRARY_PATH=$(ROOT)/usr/lib/x86_64-linux-gnu PATH=$(ROOT)/usr/bin:$(PATH) ACLOCAL_PATH=$(ROOT)/usr/share/aclocal $(MAKE) -C linux-sgx EXTRA_CXXFLAGS+="-isystem $(ROOT)/usr/include -isystem $(ROOT)/usr/include/x86_64-linux-gnu -L$(ROOT)/usr/lib/x86_64-linux-gnu" DEBUG=1 LD_LIBRARY_PATH=$(ROOT)/usr/lib/x86_64-linux-gnu:$(ROOT)/lib/x86_64-linux-gnu LIBRARY_PATH=$(ROOT)/usr/lib/x86_64-linux-gnu PATH=$(ROOT)/usr/bin:$(PATH) ACLOCAL_PATH=$(ROOT)/usr/share/aclocal $(MAKE) -C linux-sgx EXTRA_CXXFLAGS+="-isystem $(ROOT)/usr/include -isystem $(ROOT)/usr/include/x86_64-linux-gnu -L$(ROOT)/usr/lib/x86_64-linux-gnu" DEBUG=1
jdk8u: jdk8u:
hg clone http://hg.openjdk.java.net/jdk8u/jdk8u git clone -b deterministic-jvm8 --single-branch https://github.com/corda/openjdk $@
jdk8u/hotspot: | jdk8u $(JDK_IMAGE): jdk8u
cd jdk8u && $(SHELL) ./get_source.sh cd jdk8u && $(SHELL) ./configure && $(MAKE) JOBS=2 images
linux-sgx/external/ippcp_internal/inc: linux-sgx/external/ippcp_internal/inc:
cd linux-sgx && $(SHELL) ./download_prebuilt.sh cd linux-sgx && $(SHELL) ./download_prebuilt.sh
@ -38,9 +41,11 @@ build:
clean: clean:
$(MAKE) -C jvm-enclave clean $(MAKE) -C jvm-enclave clean
$(MAKE) -C linux-sgx clean $(MAKE) -C linux-sgx clean
[ ! -d jdk8u ] || $(MAKE) -C jdk8u clean
$(MAKE) -C avian clean $(MAKE) -C avian clean
.PHONY: distclean .PHONY: distclean
distclean: clean distclean: clean
rm -rf jdk8u $(RM) -r jdk8u
rm -rf linux-sgx/external/{ippcp_internal,libirc,libm} $(RM) -r linux-sgx/external/{ippcp_internal,libirc,libm}

View File

@ -4,11 +4,11 @@ The build
Prerequisites Prerequisites
------------- -------------
* Install mercurial, gcc/g++(6), autoconf, automake, ocaml, opendjk(8), libtool, python(2.7) * Install gcc/g++(6), autoconf, automake, ocaml, opendjk(8), libtool, python(2.7)
* Make sure JAVA_HOME points to your jdk 8 installation * Make sure JAVA_HOME points to your OpenJDK 8 installation
* Make sure CXX points to g++ (the project does NOT compile with other compilers like clang!) * Make sure CXX points to g++ (the project does NOT compile with other compilers like clang!)
* If your hardware supports SGX and you want to use it directly you need to install and load the sgx kernel module (verify by running `lsmod | grep isgx`) and have the sgx service running (on a systemd setup verify by running `systemctl status aesmd`). Note that this is only required for actually running the binary, the build should work fine without. * If your hardware supports SGX and you want to use it directly you need to install and load the sgx kernel module (verify by running `lsmod | grep isgx`) and have the sgx service running (on a systemd setup verify by running `systemctl status aesmd`). Note that this is only required for actually running the binary, the build should work fine without.
* The SGX SDK has a simulation mode that doesn't require hardware support. To use this edit `sgx-jvm/jvm-enclave/CMakeLists.txt` and change `set(SGX_USE_HARDWARE TRUE)` to `FALSE` * The SGX SDK has a simulation mode that doesn't require hardware support. To use this edit `sgx-jvm/jvm-enclave/common/CMakeLists.txt` and change `set(SGX_USE_HARDWARE TRUE)` to `FALSE`
Toplevel Makefile targets Toplevel Makefile targets
------------------------- -------------------------

View File

@ -127,7 +127,7 @@ public class ConstantPool {
public void writeTo(OutputStream out) throws IOException { public void writeTo(OutputStream out) throws IOException {
write1(out, CONSTANT_Utf8); write1(out, CONSTANT_Utf8);
byte[] bytes = data.getBytes(); byte[] bytes = data.getBytes("UTF-8");
write2(out, bytes.length); write2(out, bytes.length);
out.write(bytes); out.write(bytes);
} }

View File

@ -1,71 +0,0 @@
/* Copyright (c) 2008-2015, Avian Contributors
Permission to use, copy, modify, and/or distribute this software
for any purpose with or without fee is hereby granted, provided
that the above copyright notice and this permission notice appear
in all copies.
There is NO WARRANTY for this software. See license.txt for
details. */
package avian;
import java.net.InetSocketAddress;
import java.nio.ByteBuffer;
import java.nio.channels.ServerSocketChannel;
import java.nio.channels.SocketChannel;
public class Traces {
private static final String Newline = System.getProperty("line.separator");
private static String traceAllThreads() {
StringBuilder buffer = new StringBuilder();
Thread[] threads = new Thread[Thread.activeCount()];
int count = Thread.enumerate(threads);
for (int i = 0; i < count; ++i) {
traceThread(threads[i], buffer);
}
return buffer.toString();
}
private static String traceThread(Thread thread) {
StringBuilder buffer = new StringBuilder();
traceThread(thread, buffer);
return buffer.toString();
}
private static void traceThread(Thread thread, StringBuilder buffer) {
buffer.append(thread).append(Newline);
for (StackTraceElement e: thread.getStackTrace()) {
buffer.append("\tat ").append(e).append(Newline);
}
}
public static void startTraceListener(final String host, final int port) {
Thread t = new Thread(new Runnable() {
public void run() {
try {
ServerSocketChannel server = ServerSocketChannel.open();
server.socket().bind(new InetSocketAddress(host, port));
while (true) {
SocketChannel c = server.accept();
try {
c.write(ByteBuffer.wrap(traceAllThreads().getBytes()));
} finally {
c.close();
}
}
} catch (Exception e) {
e.printStackTrace();
}
}
});
t.setDaemon(true);
t.start();
}
}

View File

@ -38,8 +38,11 @@ public final class MethodType implements java.io.Serializable {
MethodType(String spec) { MethodType(String spec) {
this.loader = SystemClassLoader.appLoader(); this.loader = SystemClassLoader.appLoader();
this.spec = new byte[spec.length() + 1]; try {
spec.getBytes(0, spec.length(), this.spec, 0); this.spec = spec.getBytes("UTF-8");
} catch (java.io.UnsupportedEncodingException e) {
throw new IllegalStateException(e.getMessage(), e);
}
} }
public String toMethodDescriptorString() { public String toMethodDescriptorString() {
@ -94,7 +97,11 @@ public final class MethodType implements java.io.Serializable {
result = new Result(spec, rtype, type(spec).return_); result = new Result(spec, rtype, type(spec).return_);
this.spec = sb.toString().getBytes(); try {
this.spec = sb.toString().getBytes("UTF-8");
} catch (java.io.UnsupportedEncodingException e) {
throw new IllegalStateException(e.getMessage(), e);
}
} }
public static MethodType methodType(Class rtype, public static MethodType methodType(Class rtype,

View File

@ -235,6 +235,10 @@ ifneq ($(openjdk),)
javahome = "$$($(native-path) "$(openjdk)/jre")" javahome = "$$($(native-path) "$(openjdk)/jre")"
endif endif
ifeq ($(openjdk-image),)
openjdk-image = $(openjdk)/jre
endif
classpath = openjdk classpath = openjdk
boot-classpath := "$(boot-classpath)$(path-separator)$$($(native-path) "$(openjdk)/jre/lib/rt.jar")" boot-classpath := "$(boot-classpath)$(path-separator)$$($(native-path) "$(openjdk)/jre/lib/rt.jar")"
build-javahome = $(openjdk)/jre build-javahome = $(openjdk)/jre
@ -1530,7 +1534,6 @@ ifneq ($(classpath),avian)
$(classpath-src)/avian/Singleton.java \ $(classpath-src)/avian/Singleton.java \
$(classpath-src)/avian/Stream.java \ $(classpath-src)/avian/Stream.java \
$(classpath-src)/avian/SystemClassLoader.java \ $(classpath-src)/avian/SystemClassLoader.java \
$(classpath-src)/avian/Traces.java \
$(classpath-src)/avian/VMClass.java \ $(classpath-src)/avian/VMClass.java \
$(classpath-src)/avian/VMField.java \ $(classpath-src)/avian/VMField.java \
$(classpath-src)/avian/VMMethod.java \ $(classpath-src)/avian/VMMethod.java \
@ -2378,10 +2381,10 @@ $(openjdk-jar-dep):
@mkdir -p $(dir $(@)) @mkdir -p $(dir $(@))
@mkdir -p $(classpath-build) @mkdir -p $(classpath-build)
(cd $(classpath-build) && \ (cd $(classpath-build) && \
$(jar) xf "$$($(native-path) "$(openjdk)/jre/lib/rt.jar")" && \ $(jar) xf "$$($(native-path) "$(openjdk-image)/lib/rt.jar")" && \
$(jar) xf "$$($(native-path) "$(openjdk)/jre/lib/jsse.jar")" && \ $(jar) xf "$$($(native-path) "$(openjdk-image)/lib/jsse.jar")" && \
$(jar) xf "$$($(native-path) "$(openjdk)/jre/lib/jce.jar")" && \ $(jar) xf "$$($(native-path) "$(openjdk-image)/lib/jce.jar")" && \
$(jar) xf "$$($(native-path) "$(openjdk)/jre/lib/charsets.jar")" && \ $(jar) xf "$$($(native-path) "$(openjdk-image)/lib/charsets.jar")" && \
$(jar) xf "$$($(native-path) "$(openjdk)/jre/lib/ext/sunjce_provider.jar")" && \ $(jar) xf "$$($(native-path) "$(openjdk-image)/lib/resources.jar")" && \
$(jar) xf "$$($(native-path) "$(openjdk)/jre/lib/resources.jar")") $(jar) xf "$$($(native-path) "$(openjdk-image)/lib/ext/sunec.jar")")
@touch $(@) @touch $(@)

View File

@ -8,13 +8,8 @@ openjdk-sources = \
$(openjdk-src)/share/native/common/verify_stub.c \ $(openjdk-src)/share/native/common/verify_stub.c \
$(openjdk-src)/share/native/java/io/FileInputStream.c \ $(openjdk-src)/share/native/java/io/FileInputStream.c \
$(openjdk-src)/share/native/java/io/io_util.c \ $(openjdk-src)/share/native/java/io/io_util.c \
$(openjdk-src)/share/native/java/io/ObjectInputStream.c \
$(openjdk-src)/share/native/java/io/ObjectOutputStream.c \
$(openjdk-src)/share/native/java/io/ObjectStreamClass.c \
$(openjdk-src)/share/native/java/io/RandomAccessFile.c \
$(openjdk-src)/share/native/java/lang/Class.c \ $(openjdk-src)/share/native/java/lang/Class.c \
$(openjdk-src)/share/native/java/lang/ClassLoader.c \ $(openjdk-src)/share/native/java/lang/ClassLoader.c \
$(openjdk-src)/share/native/java/lang/Compiler.c \
$(openjdk-src)/share/native/java/lang/Double.c \ $(openjdk-src)/share/native/java/lang/Double.c \
$(openjdk-src)/share/native/java/lang/Float.c \ $(openjdk-src)/share/native/java/lang/Float.c \
$(openjdk-src)/share/native/java/lang/Object.c \ $(openjdk-src)/share/native/java/lang/Object.c \
@ -32,13 +27,9 @@ openjdk-sources = \
$(openjdk-src)/share/native/java/lang/Thread.c \ $(openjdk-src)/share/native/java/lang/Thread.c \
$(openjdk-src)/share/native/java/lang/Throwable.c \ $(openjdk-src)/share/native/java/lang/Throwable.c \
$(wildcard $(openjdk-src)/share/native/java/lang/fdlibm/src/*.c) \ $(wildcard $(openjdk-src)/share/native/java/lang/fdlibm/src/*.c) \
$(openjdk-src)/share/native/java/net/DatagramPacket.c \
$(openjdk-src)/share/native/java/net/InetAddress.c \ $(openjdk-src)/share/native/java/net/InetAddress.c \
$(openjdk-src)/share/native/java/net/Inet4Address.c \
$(openjdk-src)/share/native/java/net/Inet6Address.c \
$(openjdk-src)/share/native/java/nio/Bits.c \ $(openjdk-src)/share/native/java/nio/Bits.c \
$(openjdk-src)/share/native/java/security/AccessController.c \ $(openjdk-src)/share/native/java/security/AccessController.c \
$(wildcard $(openjdk-src)/share/native/java/sql/DriverManager.c) \
$(openjdk-src)/share/native/java/util/concurrent/atomic/AtomicLong.c \ $(openjdk-src)/share/native/java/util/concurrent/atomic/AtomicLong.c \
$(openjdk-src)/share/native/java/util/TimeZone.c \ $(openjdk-src)/share/native/java/util/TimeZone.c \
$(openjdk-src)/share/native/java/util/zip/Adler32.c \ $(openjdk-src)/share/native/java/util/zip/Adler32.c \
@ -47,7 +38,6 @@ openjdk-sources = \
$(openjdk-src)/share/native/java/util/zip/Inflater.c \ $(openjdk-src)/share/native/java/util/zip/Inflater.c \
$(openjdk-src)/share/native/java/util/zip/ZipFile.c \ $(openjdk-src)/share/native/java/util/zip/ZipFile.c \
$(openjdk-src)/share/native/java/util/zip/zip_util.c \ $(openjdk-src)/share/native/java/util/zip/zip_util.c \
$(openjdk-src)/share/native/sun/management/VMManagementImpl.c \
$(openjdk-src)/share/native/sun/misc/GC.c \ $(openjdk-src)/share/native/sun/misc/GC.c \
$(openjdk-src)/share/native/sun/misc/MessageUtils.c \ $(openjdk-src)/share/native/sun/misc/MessageUtils.c \
$(openjdk-src)/share/native/sun/misc/NativeSignalHandler.c \ $(openjdk-src)/share/native/sun/misc/NativeSignalHandler.c \
@ -60,18 +50,12 @@ openjdk-sources = \
$(openjdk-src)/share/native/sun/reflect/Reflection.c $(openjdk-src)/share/native/sun/reflect/Reflection.c
openjdk-headers-classes = \ openjdk-headers-classes = \
java.io.Console \
java.io.FileDescriptor \ java.io.FileDescriptor \
java.io.FileInputStream \ java.io.FileInputStream \
java.io.FileOutputStream \ java.io.FileOutputStream \
java.io.FileSystem \ java.io.FileSystem \
java.io.ObjectInputStream \
java.io.ObjectOutputStream \
java.io.ObjectStreamClass \
java.io.RandomAccessFile \
java.lang.Class \ java.lang.Class \
java.lang.ClassLoader \ java.lang.ClassLoader \
java.lang.Compiler \
java.lang.Double \ java.lang.Double \
java.lang.Float \ java.lang.Float \
java.lang.Integer \ java.lang.Integer \
@ -90,17 +74,6 @@ openjdk-headers-classes = \
java.lang.reflect.Array \ java.lang.reflect.Array \
java.lang.reflect.Proxy \ java.lang.reflect.Proxy \
java.net.InetAddress \ java.net.InetAddress \
java.net.Inet4Address \
java.net.Inet6Address \
java.net.DatagramPacket \
java.net.SocketOptions \
java.net.InetAddressImplFactory \
java.net.Inet4AddressImpl \
java.net.Inet6AddressImpl \
java.net.NetworkInterface \
java.net.PlainSocketImpl \
java.net.SocketInputStream \
java.net.SocketOutputStream \
java.nio.MappedByteBuffer \ java.nio.MappedByteBuffer \
java.security.AccessController \ java.security.AccessController \
java.util.ResourceBundle \ java.util.ResourceBundle \
@ -113,7 +86,6 @@ openjdk-headers-classes = \
java.util.zip.Inflater \ java.util.zip.Inflater \
java.util.zip.ZipEntry \ java.util.zip.ZipEntry \
java.util.zip.ZipFile \ java.util.zip.ZipFile \
sun.management.VMManagementImpl \
sun.misc.GC \ sun.misc.GC \
sun.misc.MessageUtils \ sun.misc.MessageUtils \
sun.misc.NativeSignalHandler \ sun.misc.NativeSignalHandler \
@ -123,19 +95,7 @@ openjdk-headers-classes = \
sun.misc.Version \ sun.misc.Version \
sun.misc.URLClassPath \ sun.misc.URLClassPath \
sun.net.spi.DefaultProxySelector \ sun.net.spi.DefaultProxySelector \
sun.nio.ch.FileKey \
sun.nio.ch.FileChannelImpl \
sun.nio.ch.FileDispatcherImpl \
sun.nio.ch.DatagramChannelImpl \
sun.nio.ch.DatagramDispatcher \
sun.nio.ch.IOStatus \ sun.nio.ch.IOStatus \
sun.nio.ch.IOUtil \
sun.nio.ch.Net \
sun.nio.ch.ServerSocketChannelImpl \
sun.nio.ch.SocketChannelImpl \
sun.nio.ch.SocketDispatcher \
sun.nio.ch.PollArrayWrapper \
sun.nio.ch.NativeThread \
sun.reflect.ConstantPool \ sun.reflect.ConstantPool \
sun.reflect.NativeConstructorAccessorImpl \ sun.reflect.NativeConstructorAccessorImpl \
sun.reflect.NativeMethodAccessorImpl \ sun.reflect.NativeMethodAccessorImpl \
@ -159,7 +119,6 @@ openjdk-cflags = \
"-I$(openjdk-src)/share/native/java/lang/fdlibm/include" \ "-I$(openjdk-src)/share/native/java/lang/fdlibm/include" \
"-I$(openjdk-src)/share/native/java/net" \ "-I$(openjdk-src)/share/native/java/net" \
"-I$(openjdk-src)/share/native/java/util/zip" \ "-I$(openjdk-src)/share/native/java/util/zip" \
"-I$(openjdk-src)/share/native/sun/management" \
"-I$(openjdk-src)/share/native/sun/nio/ch" \ "-I$(openjdk-src)/share/native/sun/nio/ch" \
"-I$(openjdk-src)/share/javavm/include" \ "-I$(openjdk-src)/share/javavm/include" \
-D_LITTLE_ENDIAN \ -D_LITTLE_ENDIAN \
@ -181,44 +140,16 @@ ifeq ($(platform),windows)
openjdk-sources += \ openjdk-sources += \
$(openjdk-src)/windows/native/common/jni_util_md.c \ $(openjdk-src)/windows/native/common/jni_util_md.c \
$(openjdk-src)/windows/native/java/io/canonicalize_md.c \ $(openjdk-src)/windows/native/java/io/canonicalize_md.c \
$(openjdk-src)/windows/native/java/io/Console_md.c \
$(openjdk-src)/windows/native/java/io/FileDescriptor_md.c \ $(openjdk-src)/windows/native/java/io/FileDescriptor_md.c \
$(openjdk-src)/windows/native/java/io/FileInputStream_md.c \ $(openjdk-src)/windows/native/java/io/FileInputStream_md.c \
$(openjdk-src)/windows/native/java/io/FileOutputStream_md.c \ $(openjdk-src)/windows/native/java/io/FileOutputStream_md.c \
$(openjdk-src)/windows/native/java/io/io_util_md.c \ $(openjdk-src)/windows/native/java/io/io_util_md.c \
$(openjdk-src)/windows/native/java/io/RandomAccessFile_md.c \
$(openjdk-src)/windows/native/java/io/WinNTFileSystem_md.c \ $(openjdk-src)/windows/native/java/io/WinNTFileSystem_md.c \
$(openjdk-src)/windows/native/java/lang/java_props_md.c \ $(openjdk-src)/windows/native/java/lang/java_props_md.c \
$(openjdk-src)/windows/native/java/lang/ProcessEnvironment_md.c \
$(openjdk-src)/windows/native/java/lang/ProcessImpl_md.c \
$(openjdk-src)/windows/native/java/net/net_util_md.c \
$(openjdk-src)/windows/native/java/net/ExtendedOptionsImpl.c \
$(openjdk-src)/windows/native/java/net/DualStackPlainSocketImpl.c \
$(openjdk-src)/windows/native/java/net/InetAddressImplFactory.c \
$(openjdk-src)/windows/native/java/net/Inet4AddressImpl.c \
$(openjdk-src)/windows/native/java/net/Inet6AddressImpl.c \
$(openjdk-src)/windows/native/java/net/NetworkInterface.c \
$(openjdk-src)/windows/native/java/net/NetworkInterface_winXP.c \
$(openjdk-src)/windows/native/java/net/SocketInputStream.c \
$(openjdk-src)/windows/native/java/net/SocketOutputStream.c \
$(openjdk-src)/windows/native/java/net/TwoStacksPlainDatagramSocketImpl.c \
$(openjdk-src)/windows/native/java/net/TwoStacksPlainSocketImpl.c \
$(openjdk-src)/windows/native/java/util/WindowsPreferences.c \ $(openjdk-src)/windows/native/java/util/WindowsPreferences.c \
$(openjdk-src)/windows/native/java/util/logging.c \ $(openjdk-src)/windows/native/java/util/logging.c \
$(openjdk-src)/windows/native/java/util/TimeZone_md.c \ $(openjdk-src)/windows/native/java/util/TimeZone_md.c \
$(openjdk-src)/windows/native/sun/io/Win32ErrorMode.c \ $(openjdk-src)/windows/native/sun/io/Win32ErrorMode.c \
$(openjdk-src)/windows/native/sun/nio/ch/DatagramChannelImpl.c \
$(openjdk-src)/windows/native/sun/nio/ch/DatagramDispatcher.c \
$(openjdk-src)/windows/native/sun/nio/ch/FileChannelImpl.c \
$(openjdk-src)/windows/native/sun/nio/ch/FileDispatcherImpl.c \
$(openjdk-src)/windows/native/sun/nio/ch/FileKey.c \
$(openjdk-src)/windows/native/sun/nio/ch/IOUtil.c \
$(openjdk-src)/windows/native/sun/nio/ch/Net.c \
$(openjdk-src)/windows/native/sun/nio/ch/ServerSocketChannelImpl.c \
$(openjdk-src)/windows/native/sun/nio/ch/SocketChannelImpl.c \
$(openjdk-src)/windows/native/sun/nio/ch/SocketDispatcher.c \
$(openjdk-src)/windows/native/sun/nio/ch/WindowsSelectorImpl.c \
$(openjdk-src)/windows/native/sun/nio/fs/WindowsNativeDispatcher.c \
$(openjdk-src)/windows/native/sun/security/provider/WinCAPISeedGenerator.c $(openjdk-src)/windows/native/sun/security/provider/WinCAPISeedGenerator.c
ifeq (7,$(openjdk-version)) ifeq (7,$(openjdk-version))
@ -228,14 +159,7 @@ ifeq ($(platform),windows)
endif endif
openjdk-headers-classes += \ openjdk-headers-classes += \
java.net.DualStackPlainSocketImpl \ sun.io.Win32ErrorMode
java.net.SocketImpl \
java.net.TwoStacksPlainDatagramSocketImpl \
java.net.TwoStacksPlainSocketImpl \
java.lang.ProcessImpl \
sun.io.Win32ErrorMode \
sun.nio.ch.WindowsSelectorImpl \
sun.nio.fs.WindowsNativeDispatcher \
openjdk-cflags += \ openjdk-cflags += \
"-I$(openjdk-src)/windows/javavm/export" \ "-I$(openjdk-src)/windows/javavm/export" \
@ -263,58 +187,24 @@ else
openjdk-sources += \ openjdk-sources += \
$(shell find $(openjdk-src)/solaris/native/common -name '*.c') \ $(shell find $(openjdk-src)/solaris/native/common -name '*.c') \
$(openjdk-src)/solaris/native/java/io/canonicalize_md.c \ $(openjdk-src)/solaris/native/java/io/canonicalize_md.c \
$(openjdk-src)/solaris/native/java/io/Console_md.c \
$(openjdk-src)/solaris/native/java/io/FileDescriptor_md.c \ $(openjdk-src)/solaris/native/java/io/FileDescriptor_md.c \
$(openjdk-src)/solaris/native/java/io/FileInputStream_md.c \ $(openjdk-src)/solaris/native/java/io/FileInputStream_md.c \
$(openjdk-src)/solaris/native/java/io/FileOutputStream_md.c \ $(openjdk-src)/solaris/native/java/io/FileOutputStream_md.c \
$(wildcard $(openjdk-src)/solaris/native/java/io/FileSystem_md.c) \ $(wildcard $(openjdk-src)/solaris/native/java/io/FileSystem_md.c) \
$(openjdk-src)/solaris/native/java/io/io_util_md.c \ $(openjdk-src)/solaris/native/java/io/io_util_md.c \
$(openjdk-src)/solaris/native/java/io/RandomAccessFile_md.c \
$(openjdk-src)/solaris/native/java/io/UnixFileSystem_md.c \ $(openjdk-src)/solaris/native/java/io/UnixFileSystem_md.c \
$(openjdk-src)/solaris/native/java/lang/java_props_md.c \ $(openjdk-src)/solaris/native/java/lang/java_props_md.c \
$(wildcard $(openjdk-src)/solaris/native/java/lang/childproc.c) \ $(wildcard $(openjdk-src)/solaris/native/java/lang/childproc.c) \
$(openjdk-src)/solaris/native/java/lang/ProcessEnvironment_md.c \
$(openjdk-src)/solaris/native/java/lang/UNIXProcess_md.c \
$(openjdk-src)/solaris/native/java/net/net_util_md.c \
$(openjdk-src)/solaris/native/java/net/ExtendedOptionsImpl.c \
$(openjdk-src)/solaris/native/java/net/InetAddressImplFactory.c \
$(openjdk-src)/solaris/native/java/net/Inet4AddressImpl.c \
$(openjdk-src)/solaris/native/java/net/Inet6AddressImpl.c \
$(openjdk-src)/solaris/native/java/net/NetworkInterface.c \
$(openjdk-src)/solaris/native/java/net/PlainSocketImpl.c \
$(openjdk-src)/solaris/native/java/net/PlainDatagramSocketImpl.c \
$(openjdk-src)/solaris/native/java/net/SocketInputStream.c \
$(openjdk-src)/solaris/native/java/net/SocketOutputStream.c \
$(openjdk-src)/solaris/native/java/nio/MappedByteBuffer.c \ $(openjdk-src)/solaris/native/java/nio/MappedByteBuffer.c \
$(openjdk-src)/solaris/native/java/util/FileSystemPreferences.c \ $(openjdk-src)/solaris/native/java/util/FileSystemPreferences.c \
$(openjdk-src)/solaris/native/java/util/logging.c \ $(openjdk-src)/solaris/native/java/util/logging.c \
$(openjdk-src)/solaris/native/java/util/TimeZone_md.c \ $(openjdk-src)/solaris/native/java/util/TimeZone_md.c
$(openjdk-src)/solaris/native/sun/net/dns/ResolverConfigurationImpl.c \
$(openjdk-src)/solaris/native/sun/net/spi/DefaultProxySelector.c \
$(openjdk-src)/solaris/native/sun/nio/ch/DatagramChannelImpl.c \
$(openjdk-src)/solaris/native/sun/nio/ch/DatagramDispatcher.c \
$(openjdk-src)/solaris/native/sun/nio/ch/FileChannelImpl.c \
$(openjdk-src)/solaris/native/sun/nio/ch/FileDispatcherImpl.c \
$(openjdk-src)/solaris/native/sun/nio/ch/FileKey.c \
$(openjdk-src)/solaris/native/sun/nio/ch/IOUtil.c \
$(openjdk-src)/solaris/native/sun/nio/ch/Net.c \
$(openjdk-src)/solaris/native/sun/nio/ch/ServerSocketChannelImpl.c \
$(openjdk-src)/solaris/native/sun/nio/ch/SocketChannelImpl.c \
$(openjdk-src)/solaris/native/sun/nio/ch/SocketDispatcher.c \
$(openjdk-src)/solaris/native/sun/nio/ch/PollArrayWrapper.c \
$(openjdk-src)/solaris/native/sun/nio/ch/InheritedChannel.c \
$(openjdk-src)/solaris/native/sun/nio/ch/NativeThread.c \
$(openjdk-src)/solaris/native/sun/nio/fs/UnixNativeDispatcher.c \
openjdk-headers-classes += \ openjdk-headers-classes += \
java.net.PlainDatagramSocketImpl \ java.io.UnixFileSystem
java.io.UnixFileSystem \
sun.nio.ch.InheritedChannel \
sun.nio.fs.UnixNativeDispatcher \
ifneq (7,$(openjdk-version)) ifneq (7,$(openjdk-version))
openjdk-headers-classes += \ openjdk-headers-classes +=
jdk.net.SocketFlow
endif endif
openjdk-cflags += \ openjdk-cflags += \
@ -337,11 +227,9 @@ else
ifeq ($(platform),linux) ifeq ($(platform),linux)
openjdk-sources += \ openjdk-sources += \
$(openjdk-src)/solaris/native/java/net/linux_close.c \ $(openjdk-src)/solaris/native/java/net/linux_close.c
$(openjdk-src)/solaris/native/sun/nio/ch/EPollArrayWrapper.c
openjdk-headers-classes += \ openjdk-headers-classes +=
sun.nio.ch.EPollArrayWrapper
openjdk-cflags += \ openjdk-cflags += \
"-I$(openjdk-src)/solaris/native/common/deps/glib2" \ "-I$(openjdk-src)/solaris/native/common/deps/glib2" \
@ -370,9 +258,7 @@ else
endif endif
endif endif
openjdk-local-sources += \ openjdk-local-sources +=
$(src)/openjdk/my_net_util.c \
$(src)/openjdk/my_management.c
openjdk-c-objects = \ openjdk-c-objects = \
$(foreach x,$(1),$(patsubst $(2)/%.c,$(3)/%-openjdk.o,$(x))) $(foreach x,$(1),$(patsubst $(2)/%.c,$(3)/%-openjdk.o,$(x)))

View File

@ -380,9 +380,6 @@ class MyClasspath : public Classpath {
sb.append("/lib/jce.jar"); sb.append("/lib/jce.jar");
sb.append(s->pathSeparator()); sb.append(s->pathSeparator());
sb.append(javaHome); sb.append(javaHome);
sb.append("/lib/ext/sunjce_provider.jar");
sb.append(s->pathSeparator());
sb.append(javaHome);
sb.append("/lib/resources.jar"); sb.append("/lib/resources.jar");
sb.append('\0'); sb.append('\0');
@ -1989,10 +1986,6 @@ int64_t JNICALL getBootstrapResources(Thread* t, object, uintptr_t* arguments)
} }
} }
extern "C" AVIAN_EXPORT jint JNICALL net_JNI_OnLoad(JavaVM*, void*);
extern "C" AVIAN_EXPORT jint JNICALL management_JNI_OnLoad(JavaVM*, void*);
void JNICALL loadLibrary(Thread* t, object, uintptr_t* arguments) void JNICALL loadLibrary(Thread* t, object, uintptr_t* arguments)
{ {
Thread::LibraryLoadStack stack( Thread::LibraryLoadStack stack(
@ -2008,43 +2001,7 @@ void JNICALL loadLibrary(Thread* t, object, uintptr_t* arguments)
bool absolute = arguments[2]; bool absolute = arguments[2];
if (not absolute) { if (not absolute) {
if (strcmp(RUNTIME_ARRAY_BODY(n), "net") == 0) { if (strcmp(RUNTIME_ARRAY_BODY(n), "zip") == 0
bool ran;
{
ACQUIRE(t, t->m->classLock);
local::MyClasspath* c
= static_cast<local::MyClasspath*>(t->m->classpath);
ran = c->ranNetOnLoad;
c->ranNetOnLoad = true;
}
if (not ran) {
net_JNI_OnLoad(t->m, 0);
}
return;
} else if (strcmp(RUNTIME_ARRAY_BODY(n), "management") == 0) {
bool ran;
{
ACQUIRE(t, t->m->classLock);
local::MyClasspath* c
= static_cast<local::MyClasspath*>(t->m->classpath);
ran = c->ranManagementOnLoad;
c->ranManagementOnLoad = true;
}
if (not ran) {
management_JNI_OnLoad(t->m, 0);
}
return;
} else if (strcmp(RUNTIME_ARRAY_BODY(n), "zip") == 0
or strcmp(RUNTIME_ARRAY_BODY(n), "nio") == 0) { or strcmp(RUNTIME_ARRAY_BODY(n), "nio") == 0) {
return; return;
} }

View File

@ -1,2 +0,0 @@
#define JNI_OnLoad management_JNI_OnLoad
#include "management.c"

View File

@ -1,20 +0,0 @@
#define JNI_OnLoad net_JNI_OnLoad
#include "net_util.c"
#ifdef _WIN32
#undef IN6_SET_ADDR_UNSPECIFIED
#define IN6_SET_ADDR_UNSPECIFIED(a) \
memset((a)->s6_bytes,0,sizeof(struct in6_addr))
void
IN6ADDR_SETANY(struct sockaddr_in6 *a)
{
a->sin6_family = AF_INET6;
a->sin6_port = 0;
a->sin6_flowinfo = 0;
IN6_SET_ADDR_UNSPECIFIED(&a->sin6_addr);
a->sin6_scope_id = 0;
}
#endif

View File

@ -1,3 +1,4 @@
import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.nio.BufferUnderflowException; import java.nio.BufferUnderflowException;
import java.nio.BufferOverflowException; import java.nio.BufferOverflowException;
@ -8,31 +9,31 @@ public class Buffers {
System.loadLibrary("test"); System.loadLibrary("test");
} }
private static void testArrays(Factory factory1, Factory factory2) { private static void testArrays(Factory factory1, Factory factory2) throws IOException {
final int size = 64; final int size = 64;
ByteBuffer b1 = factory1.allocate(size); ByteBuffer b1 = factory1.allocate(size);
ByteBuffer b2 = factory2.allocate(size); ByteBuffer b2 = factory2.allocate(size);
String s = "1234567890abcdefghijklmnopqrstuvwxyz"; String s = "1234567890abcdefghijklmnopqrstuvwxyz";
b1.put(s.getBytes()); b1.put(s.getBytes("UTF-8"));
b1.flip(); b1.flip();
byte[] ba = new byte[s.length()]; byte[] ba = new byte[s.length()];
b1.get(ba); b1.get(ba);
assertEquals(s, new String(ba)); assertEquals(s, new String(ba, "UTF-8"));
b1.position(0); b1.position(0);
b2.put(b1); b2.put(b1);
b2.flip(); b2.flip();
b2.get(ba); b2.get(ba);
assertEquals(s, new String(ba)); assertEquals(s, new String(ba, "UTF-8"));
b1.position(0); b1.position(0);
b2.position(0); b2.position(0);
b1.limit(b1.capacity()); b1.limit(b1.capacity());
b2.limit(b2.capacity()); b2.limit(b2.capacity());
b1.put(s.getBytes(), 4, 5); b1.put(s.getBytes("UTF-8"), 4, 5);
b1.flip(); b1.flip();
ba = new byte[5]; ba = new byte[5];
b1.get(ba); b1.get(ba);
assertEquals(s.substring(4, 9), new String(ba)); assertEquals(s.substring(4, 9), new String(ba, "UTF-8"));
} }
private static void testPrimativeGetAndSet(Factory factory1, Factory factory2) { private static void testPrimativeGetAndSet(Factory factory1, Factory factory2) {

View File

@ -1,100 +0,0 @@
import java.net.SocketAddress;
import java.net.InetSocketAddress;
import java.net.ProtocolFamily;
import java.net.StandardProtocolFamily;
import java.nio.ByteBuffer;
import java.nio.channels.DatagramChannel;
import java.nio.channels.Selector;
import java.nio.channels.SelectionKey;
public class Datagrams {
private static void expect(boolean v) {
if (! v) throw new RuntimeException();
}
private static boolean equal(byte[] a, int aOffset, byte[] b, int bOffset,
int length)
{
for (int i = 0; i < length; ++i) {
if (a[aOffset + i] != b[bOffset + i]) return false;
}
return true;
}
public static void main(String[] args) throws Exception {
test(true);
test(false);
}
private static void test(boolean send) throws Exception {
final String Hostname = "localhost";
final int InPort = 22043;
final int OutPort = 22044;
final SocketAddress InAddress = new InetSocketAddress(Hostname, InPort);
final SocketAddress OutAddress = new InetSocketAddress(Hostname, OutPort);
final byte[] Message = "hello, world!".getBytes();
DatagramChannel out = DatagramChannel.open();
try {
out.configureBlocking(false);
out.socket().bind(OutAddress);
if (! send) out.connect(InAddress);
DatagramChannel in = DatagramChannel.open();
try {
in.configureBlocking(false);
in.socket().bind(InAddress);
Selector selector = Selector.open();
try {
SelectionKey outKey = out.register
(selector, SelectionKey.OP_WRITE, null);
SelectionKey inKey = in.register
(selector, SelectionKey.OP_READ, null);
int state = 0;
ByteBuffer inBuffer = ByteBuffer.allocate(Message.length);
loop: while (true) {
selector.select();
switch (state) {
case 0: {
if (outKey.isWritable()) {
if (send) {
out.send(ByteBuffer.wrap(Message), InAddress);
} else {
out.write(ByteBuffer.wrap(Message));
}
state = 1;
}
} break;
case 1: {
if (inKey.isReadable()) {
expect(in.receive(inBuffer).equals(OutAddress));
if (! inBuffer.hasRemaining()) {
expect(equal(inBuffer.array(),
inBuffer.arrayOffset(),
Message,
0,
Message.length));
break loop;
}
}
} break;
default: throw new RuntimeException();
}
}
} finally {
selector.close();
}
} finally {
in.close();
}
} finally {
out.close();
}
}
}

View File

@ -1,47 +0,0 @@
import java.io.FileOutputStream;
import java.io.FileInputStream;
import java.io.File;
import java.io.IOException;
public class FileOutput {
private static void expect(boolean v) {
if (! v) throw new RuntimeException();
}
private static void test(boolean appendFirst) throws IOException {
try {
FileOutputStream f = new FileOutputStream("test.txt", appendFirst);
f.write("Hello world!\n".getBytes());
f.close();
FileOutputStream f2 = new FileOutputStream("test.txt", true);
f2.write("Hello world again!".getBytes());
f2.close();
FileInputStream in = new FileInputStream("test.txt");
byte[] buffer = new byte[256];
int c;
int offset = 0;
while ((c = in.read(buffer, offset, buffer.length - offset)) != -1) {
offset += c;
}
in.close();
if (! "Hello world!\nHello world again!".equals
(new String(buffer, 0, offset)))
{
throw new RuntimeException();
}
} finally {
expect(new File("test.txt").delete());
}
}
public static void main(String[] args) throws IOException {
expect(new File("nonexistent-file").length() == 0);
test(false);
test(true);
}
}

View File

@ -35,62 +35,32 @@ public class Files {
} }
} }
private static void setExecutableTestWithPermissions(boolean executable)
throws Exception
{
File file = File.createTempFile("avian.", null);
try {
file.setExecutable(executable);
if (executable) {
expect(file.canExecute());
} else {
// Commented out because this will fail on Windows - both on Avian and on OpenJDK
// The implementation for Windows considers canExecute() to be the same as canRead()
// expect(!file.canExecute());
}
} finally {
expect(file.delete());
}
}
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
isAbsoluteTest(true); isAbsoluteTest(true);
isAbsoluteTest(false); isAbsoluteTest(false);
setExecutableTestWithPermissions(true);
setExecutableTestWithPermissions(false);
isRootParent(); isRootParent();
{ File f = new File("test.txt");
f.createNewFile();
expect(! f.createNewFile());
f.delete();
}
{ File f = new File("test.txt"); { File f = new File("test.txt");
FileOutputStream out = new FileOutputStream(f); FileOutputStream out = new FileOutputStream(f);
byte[] message = "hello, world!\n".getBytes("UTF-8");
out.write(message);
out.close();
expect(f.lastModified() > 0);
FileInputStream in = new FileInputStream(f);
try { try {
byte[] message = "hello, world!\n".getBytes(); expect(in.available() == message.length);
out.write(message);
out.close();
expect(f.lastModified() > 0); for (int i = 0; i < message.length; ++i) {
in.read();
FileInputStream in = new FileInputStream(f); expect(in.available() == message.length - i - 1);
try {
expect(in.available() == message.length);
for (int i = 0; i < message.length; ++i) {
in.read();
expect(in.available() == message.length - i - 1);
}
expect(in.read() == -1);
expect(in.available() == 0);
} finally {
in.close();
} }
expect(in.read() == -1);
expect(in.available() == 0);
} finally { } finally {
f.delete(); in.close();
} }
} }

View File

@ -33,35 +33,6 @@ public class Integers {
expect(Integer.numberOfLeadingZeros(negative) == 0); expect(Integer.numberOfLeadingZeros(negative) == 0);
negative += ((int)Math.pow(2, i)); negative += ((int)Math.pow(2, i));
} }
for(int i = 0; i < 99999; i++) {
String binary = "";
int nolz = 0;
boolean nolzFound = false;
for(int j = 0; j < 31; j++) {
double r = Math.random();
if(r < 0.5) {
binary += "0";
if(!nolzFound) {
nolz++;
}
} else {
binary += "1";
nolzFound = true;
}
}
double r = Math.random();
if(r < 0.5) {
// positive
binary = "0" + binary;
nolz++;
expect(Integer.numberOfLeadingZeros(Integer.parseInt(binary, 2)) == nolz);
} else {
// negative
expect(Integer.numberOfLeadingZeros(-Integer.parseInt(binary, 2)) == 0);
}
}
} }
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {

View File

@ -313,19 +313,6 @@ public class Misc {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
// as of this writing, we don't support URLs on Android, since it
// pulls in a third-party library we don't include:
if (! "http://www.android.com/".equals
(System.getProperty("java.vendor.url")))
{
expect(new URL("http://oss.readytalk.com")
.getHost().equals("oss.readytalk.com"));
}
expect(java.util.Arrays.equals
(new byte[] { 0, 0, 0, 0 },
java.net.InetAddress.getByName("0.0.0.0").getAddress()));
expect(! staticRan); expect(! staticRan);
Static.run(); Static.run();
expect(staticRan); expect(staticRan);

View File

@ -1,31 +0,0 @@
import java.io.IOException;
public class Processes {
public static void main(String[] args) {
long start = System.currentTimeMillis();
try {
final Process p = Runtime.getRuntime().exec("sleep 10");
new Thread() {
public void run() {
try {
Thread.sleep(100);
} catch(InterruptedException e) {
// ignore
}
p.destroy();
}
}.start();
try {
p.waitFor();
} catch(InterruptedException e) {
// ignore
}
long stop = System.currentTimeMillis();
if(stop - start > 5000) {
throw new RuntimeException("test failed; we didn't kill the process...");
}
} catch(IOException e) {
throw new RuntimeException(e);
}
}
}

View File

@ -1,231 +0,0 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
import java.util.Properties;
public class Serialize implements Serializable {
public static final long serialVersionUID = 1l;
public int dummy = 0x12345678;
private static void expect(boolean v) {
if (! v) throw new RuntimeException();
}
private static void expectEqual(boolean a, boolean b) {
expect(a == b);
}
private static void expectEqual(int a, int b) {
expect(a == b);
}
private static void expectEqual(String a, String b) {
expect(a.equals(b));
}
private static String pad(long number, int length) {
return pad(Long.toHexString(number), length, '0');
}
private static String pad(String s, int length, char padChar) {
length -= s.length();
if (length <= 0) {
return s;
}
StringBuilder builder = new StringBuilder();
while (length-- > 0) {
builder.append(padChar);
}
return builder.append(s).toString();
}
protected static void hexdump(byte[] a) {
StringBuilder builder = new StringBuilder();
System.err.print(pad(0, 8) + " ");
for (int i = 0; i < a.length; i++) {
String hex = Integer.toHexString(a[i] & 0xff);
System.err.print(" " + (hex.length() == 1 ? "0" : "") + hex);
builder.append(a[i] < 0x20 || a[i] > 0x7f ? '.' : (char)a[i]);
if ((i & 0xf) == 0x7) {
System.err.print(" ");
} else if ((i & 0xf) == 0xf) {
System.err.println(" |" + builder + "|");
builder.setLength(0);
System.err.print(pad(i + 1, 8) + " ");
}
}
for (int i = a.length & 0xf; i < 0x10; i++) {
System.err.print(" ");
if ((i & 0xf) == 0x7) {
System.err.print(" ");
}
}
System.err.println(" |" + builder + "|");
}
private static void expectEqual(byte[] a, int[] b) {
expect(a.length == b.length);
for (int i = 0; i < a.length; ++i) {
expect(a[i] == (byte)b[i]);
}
}
private static class MyMap implements Serializable {
private transient Properties properties = new Properties();
public final static long serialVersionUID = 0x0cc1f63e2d256ae6l;
public int size() {
return properties.size();
}
public void put(String key, String value) {
properties.put(key, value);
}
public String get(String key) {
return properties.getProperty(key);
}
private void writeObject(ObjectOutputStream out) throws IOException {
out.defaultWriteObject();
out.writeInt(size());
for (Object key : properties.keySet()) {
out.writeObject(key);
out.writeObject(properties.get(key));
}
}
private void readObject(ObjectInputStream in) throws IOException {
try {
in.defaultReadObject();
} catch (Exception e) {
// OpenJDK's defaultReadObject() can throw a ClassNotFoundException
throw new IOException(e);
}
properties = new Properties();
int size = in.readInt();
for (int i = 0; i < size; i++) try {
properties.put(in.readObject(), in.readObject());
} catch (ClassNotFoundException e) {
throw new IOException(e);
}
}
}
public static void main(String[] args) throws Exception {
ByteArrayOutputStream out = new ByteArrayOutputStream();
ObjectOutputStream out2 = new ObjectOutputStream(out);
out2.writeBoolean(true);
out2.flush();
out2.writeByte(17);
out2.flush();
out2.writeInt(0xcafebabe);
out2.flush();
out2.writeUTF("Max & Möritz");
out2.flush();
out2.writeChar('ɛ');
out2.flush();
out2.writeObject(new Serialize());
out2.close();
byte[] array = out.toByteArray();
expectEqual(array, new int[] {
// magic
0xac, 0xed,
// version
0x00, 0x05,
// blockdata, length
0x77, 0x1,
// true
1,
// blockdata, length
0x77, 0x1,
// (byte)17
17,
// blockdata, length
0x77, 0x4,
// 0xcafebabe
0xca, 0xfe, 0xba, 0xbe,
// blockdata, length
0x77, 0xf,
// "Max & Möritz"
0x0, 0xd, 'M', 'a', 'x', ' ', '&', ' ', 'M', 0xc3, 0xb6, 'r', 'i', 't', 'z',
// blockdata, length
0x77, 0x2,
// 'ö'
0x02, 0x5b,
// object
0x73,
// class desc, "Serialize"
0x72, 0, 9, 'S', 'e', 'r', 'i', 'a', 'l', 'i', 'z', 'e',
// serialVersionUID
0, 0, 0, 0, 0, 0, 0, 1,
// flags (SC_SERIALIZABLE)
2,
// field count
0x0, 0x1,
// int dummy
'I', 0x0, 0x5, 'd', 'u', 'm', 'm', 'y',
// class annotation
0x78,
// super class desc
0x70,
// classdata[]
0x12, 0x34, 0x56, 0x78
});
ByteArrayInputStream in = new ByteArrayInputStream(array);
ObjectInputStream in2 = new ObjectInputStream(in);
expectEqual(true, in2.readBoolean());
expectEqual(17, in2.readByte());
expectEqual(0xcafebabe, in2.readInt());
expectEqual("Max & Möritz", in2.readUTF());
expectEqual('ɛ', in2.readChar());
Serialize unserialized = (Serialize) in2.readObject();
expectEqual(0x12345678, unserialized.dummy);
in2.close();
out.reset();
out2 = new ObjectOutputStream(out);
MyMap map = new MyMap();
map.put("key", "value");
out2.writeObject(map);
out2.close();
array = out.toByteArray();
expectEqual(array, new int[] {
// magic
0xac, 0xed,
// version
0x00, 0x05,
// object
0x73,
// class desc "Serialize$MyMap"
0x72, 0, 15, 'S', 'e', 'r', 'i', 'a', 'l', 'i', 'z', 'e', '$',
'M', 'y', 'M', 'a', 'p',
// serial version UID: 0x0cc1f64e2d266ae6
0x0c, 0xc1, 0xf6, 0x3e, 0x2d, 0x25, 0x6a, 0xe6,
// flags: SC_SERIALIZABLE | SC_WRITE_METHOD
0x03,
// no (non-transient) fields
0, 0,
// class annotation
0x78,
// super class desc
0x70,
// custom TreeMap data written by TreeMap#writeObject
0x77, 4, 0x00 , 0x00, 0x00, 0x01, // (int)1 (== map.size())
0x74, 0, 3, 'k', 'e', 'y', // "key"
0x74, 0, 5, 'v', 'a', 'l', 'u', 'e', // "value"
// end block data
0x78
});
in = new ByteArrayInputStream(array);
in2 = new ObjectInputStream(in);
map = (MyMap)in2.readObject();
in2.close();
expectEqual(1, map.size());
expectEqual("value", (String)map.get("key"));
}
}

View File

@ -1,33 +0,0 @@
import java.net.SocketAddress;
import java.net.InetSocketAddress;
import java.nio.channels.SocketChannel;
import java.io.IOException;
public class Sockets {
private static void expect(boolean v) {
if (! v) throw new RuntimeException();
}
public static void testFailedBind() throws Exception {
final String Hostname = "localhost";
final int Port = 22046; // hopefully this port is unused
final SocketAddress Address = new InetSocketAddress(Hostname, Port);
final byte[] Message = "hello, world!".getBytes();
SocketChannel out = SocketChannel.open();
try {
try {
out.connect(Address);
expect(false);
} catch(IOException e) {
// We're good. This previously triggered a vm assert, rather than an exception
}
} finally {
out.close();
}
}
public static void main(String[] args) throws Exception {
testFailedBind();
}
}

View File

@ -117,7 +117,7 @@ public class Strings {
public static void main(String[] args) throws Exception { public static void main(String[] args) throws Exception {
expect(new String(new byte[] { 99, 111, 109, 46, 101, 99, 111, 118, 97, expect(new String(new byte[] { 99, 111, 109, 46, 101, 99, 111, 118, 97,
116, 101, 46, 110, 97, 116, 46, 98, 117, 116, 101, 46, 110, 97, 116, 46, 98, 117,
115, 46, 83, 121, 109, 98, 111, 108 }) 115, 46, 83, 121, 109, 98, 111, 108 }, "UTF-8")
.equals("com.ecovate.nat.bus.Symbol")); .equals("com.ecovate.nat.bus.Symbol"));
final String months = "Jan\u00aeFeb\u00aeMar\u00ae"; final String months = "Jan\u00aeFeb\u00aeMar\u00ae";
@ -224,7 +224,7 @@ public class Strings {
{ String s = "hello, world!"; { String s = "hello, world!";
java.nio.CharBuffer buffer = java.nio.CharBuffer.allocate(s.length()); java.nio.CharBuffer buffer = java.nio.CharBuffer.allocate(s.length());
new java.io.InputStreamReader new java.io.InputStreamReader
(new java.io.ByteArrayInputStream(s.getBytes())).read(buffer); (new java.io.ByteArrayInputStream(s.getBytes("UTF-8"))).read(buffer);
expect(s.equals(new String(buffer.array()))); expect(s.equals(new String(buffer.array())));
} }
} }

View File

@ -1,113 +0,0 @@
public class Trace implements Runnable {
private volatile boolean alive = true;
private static void throwSomething() {
throw new RuntimeException();
}
private void bar(Object o) {
o.toString();
}
private void foo() {
{ long a = 42;
long b = 25;
long c = a / b;
}
try {
long a = 42;
long b = 0;
long c = a / b;
} catch (Exception e) { }
try {
throw new Exception();
} catch (Exception e) { }
try {
throwSomething();
} catch (Exception e) { }
try {
Trace.class.getMethod("bar", Object.class).invoke(this, this);
} catch (Exception e) { }
}
private static void dummy() {
byte[] a = new byte[10];
byte[] b = new byte[10];
System.arraycopy(a, 0, b, 0, 10);
}
private static void tail1(int a, int b, int c, int d, int e, int f) {
dummy();
}
private static void tail2() {
tail1(1, 2, 3, 4, 5, 6);
tail1(1, 2, 3, 4, 5, 6);
}
private static void test(Trace trace) {
tail1(1, 2, 3, 4, 5, 6);
tail2();
trace.foo();
}
public void run() {
synchronized (this) {
notifyAll();
}
try {
for (int i = 0; i < 10000; ++i) {
test(this);
if (i % 100 == 0) {
System.out.print("r");
System.out.flush();
synchronized (this) {
notifyAll();
}
}
}
} finally {
synchronized (this) {
alive = false;
notifyAll();
}
}
}
public static void main(String[] args) throws Exception {
if ("true".equals(System.getenv("TRAVIS"))) {
// This test fails randomly on Travis-CI, though we've never
// been able to reproduce the failure elsewhere. So we disable
// it if we know we're running on Travis.
return;
}
Trace trace = new Trace();
Thread thread = new Thread(trace);
synchronized (trace) {
thread.start();
trace.wait();
int count = 0;
while (trace.alive) {
thread.getStackTrace();
++ count;
if (count % 100 == 0) {
trace.wait();
System.out.print("t");
System.out.flush();
}
}
System.out.println("\ngot " + count + " traces");
}
}
}

View File

@ -1,214 +0,0 @@
import java.io.BufferedReader;
import java.io.File;
import java.io.FileOutputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.zip.*;
public class ZipOutputStreamTest
{
private static final String TEST1 = "test1.txt";
private static final String TEST2 = "test2.txt";
private static final String TEST3 = "test3.txt";
private static final String TEST4 = "test4.txt";
private static final String TEST1_CONTENTS = "\"this is a test\"";
private static final String TEST2_CONTENTS = "this is a\nmulti-line test";
private static final String TEST3_CONTENTS = "74 68 69 73 20 69 73 20 61 20 74 65 73 74";
private static final String TEST4_CONTENTS = "01110100 01101000 01101001 01110011 00100000 01101001 01110011 00100000 01100001 00100000 01110100 01100101 01110011 01110100";
private static final String BYTE_ZIP_PREFIX = "zosByte";
private static final String ARRAY_ZIP_PREFIX = "zosArray";
private static final String ARRAY_OFFSET_LENGTH_ZIP_PREFIX = "zosArrayOffsetLength";
private static final String ZIP_SUFFIX = ".zip";
private static final Map<String, String> FILES_CONTENTS;
static
{
Map<String, String> m = new HashMap<String, String>();
m.put(TEST1, TEST1_CONTENTS);
m.put(TEST2, TEST2_CONTENTS);
m.put(TEST3, TEST3_CONTENTS);
m.put(TEST4, TEST4_CONTENTS);
FILES_CONTENTS = Collections.unmodifiableMap(m);
}
private static enum WriteStyle {
Byte(ARRAY_ZIP_PREFIX),
Array(ARRAY_ZIP_PREFIX),
ArrayOffsetLength(ARRAY_OFFSET_LENGTH_ZIP_PREFIX);
public final String prefix;
private WriteStyle(String prefix) {
this.prefix = prefix;
}
}
private static byte[] buffer = new byte[1024];
private static void expect(boolean v) {
if (! v) throw new RuntimeException();
}
public static void main(String[] args)
throws Exception
{
List<File> zipFiles = new ArrayList<File>(2);
try {
// Test byte-at-a-time write function
File f1 = createZip(WriteStyle.Byte);
zipFiles.add(f1);
verifyContents(f1.getAbsolutePath());
// Test arraw write function
File f2 = createZip(WriteStyle.Array);
zipFiles.add(f2);
verifyContents(f2.getAbsolutePath());
// Test arraw write function
File f3 = createZip(WriteStyle.ArrayOffsetLength);
zipFiles.add(f3);
verifyContents(f3.getAbsolutePath());
} finally {
// Remove the created zip files
cleanUp(zipFiles);
}
}
private static File createZip(WriteStyle writeStyle)
throws Exception
{
FileOutputStream outputStream = null;
ZipOutputStream zipContents = null;
try
{
// Create a temporary zip file for this test
String prefix = writeStyle.prefix;
File outputZip = File.createTempFile(prefix, ZIP_SUFFIX);
System.out.println("Created " + outputZip.getAbsolutePath());
// Prepare the streams
outputStream = new FileOutputStream(outputZip);
zipContents = new ZipOutputStream(outputStream);
// Zip the file contents (convert directly from string to bytes)
long startTime = System.currentTimeMillis();
for (Map.Entry<String, String> f : FILES_CONTENTS.entrySet())
{
String name = f.getKey();
String contents = f.getValue();
System.out.println("Zipping " + name + "...");
ZipEntry entry = new ZipEntry(name);
zipContents.putNextEntry(entry);
byte[] bytesToWrite = contents.getBytes();
switch (writeStyle) {
case Byte: {
// Use the 1-parameter write method; takes a single byte
for (int i = 0; i < bytesToWrite.length; i++)
{
zipContents.write(bytesToWrite[i]);
}
} break;
case Array: {
// Use 3-parameter write method; takes a buffer, offset, and length
zipContents.write(bytesToWrite);
} break;
case ArrayOffsetLength: {
// Use 3-parameter write method; takes a buffer, offset, and length
zipContents.write(bytesToWrite, 0 , bytesToWrite.length);
} break;
default: throw new RuntimeException("unexpected write style: " + writeStyle);
}
// Done with this file
zipContents.closeEntry();
System.out.println("Done");
}
// All files have been written
long endTime = System.currentTimeMillis();
System.out.println("Finished " + outputZip.getName() + " in " + ((endTime - startTime) / 1000.0) + " seconds");
return outputZip;
}
finally
{
if (zipContents != null)
zipContents.close();
if (outputStream != null)
outputStream.close();
}
}
private static void verifyContents(String zipName)
throws Exception
{
System.out.println("Verify " + zipName);
ZipFile zf = null;
BufferedReader reader = null;
int numFilesInZip = 0;
try
{
String line;
String contents;
// Get the contents of each file in the zip
zf = new ZipFile(zipName);
for (Enumeration<? extends ZipEntry> e = zf.entries(); e.hasMoreElements();)
{
ZipEntry entry = e.nextElement();
reader = new BufferedReader(new InputStreamReader(zf.getInputStream(entry)));
contents = "";
numFilesInZip += 1;
while ((line = reader.readLine()) != null)
{
if (contents.length() > 0)
{
contents += "\n";
}
contents += line;
}
reader.close();
// Assert that this file's contents are correct
expect(contents.equals(FILES_CONTENTS.get(entry.getName())));
}
zf.close();
// Assert that the zip contained the correct number of files
expect(numFilesInZip == FILES_CONTENTS.size());
}
finally
{
if (zf != null)
zf.close();
if (reader != null)
reader.close();
}
}
private static void cleanUp(List<File> zipFiles)
throws Exception
{
for (File f : zipFiles)
{
if (f.exists())
{
f.delete();
}
}
}
}

View File

@ -47,7 +47,7 @@ public class DumpStats {
offset += c; offset += c;
} }
if (offset != b.length) throw new EOFException(); if (offset != b.length) throw new EOFException();
return new String(b); return new String(b, "UTF-8");
} }
private static Record record(Map<Integer, Record> map, int key) { private static Record record(Map<Integer, Record> map, int key) {

View File

@ -42,7 +42,7 @@ public class PrintDump {
offset += c; offset += c;
} }
if (offset != b.length) throw new EOFException(); if (offset != b.length) throw new EOFException();
return new String(b); return new String(b, "UTF-8");
} }
private static void pipe(InputStream in, PrintStream out) private static void pipe(InputStream in, PrintStream out)

View File

@ -43,7 +43,7 @@ public class QueryDump {
offset += c; offset += c;
} }
if (offset != b.length) throw new EOFException(); if (offset != b.length) throw new EOFException();
return new String(b); return new String(b, "UTF-8");
} }
private static Record record(Map<Integer, Record> map, int key) { private static Record record(Map<Integer, Record> map, int key) {

View File

@ -1,59 +0,0 @@
package extra;
import java.lang.Runtime;
import java.lang.Process;
public class RuntimeExec {
public static void main(String[] args) throws java.io.IOException, java.lang.InterruptedException {
Runtime runtime = Runtime.getRuntime();
String ieStr = null;
String charmapStr = null;
String[] firefox = new String[2];
if(System.getProperty("os.name").equals("windows")){
System.out.println("Executing internet explorer");
ieStr = "\"c:\\program files\\internet explorer\\iexplore.exe\" http://www.google.com";
} else {
System.out.println("Executing Firefox using string");
ieStr = "firefox http://www.google.com";
}
Process ie = runtime.exec(ieStr);
if(System.getProperty("os.name").equals("windows")){
System.out.println("Executing firefox");
firefox[0] = "c:\\program files\\mozilla firefox\\firefox.exe";
firefox[1] = "http://www.google.com";
} else {
System.out.println("Executing Firefox using array");
firefox[0] = "firefox";
firefox[1] = "http://www.google.com";
}
Process ff = runtime.exec(firefox);
boolean ffSuccess = false;
boolean ieSuccess = false;
while(!(ieSuccess && ffSuccess)){
if(!ffSuccess){
try{
System.out.println("Exit value from string exec: " + ff.exitValue());
ffSuccess = true;
} catch(IllegalThreadStateException e) {}
}
if(!ieSuccess){
try{
System.out.println("Exit value from array exec: " + ie.exitValue());
ieSuccess = true;
} catch(IllegalThreadStateException e) {}
}
}
if(System.getProperty("os.name").equals("windows")){
System.out.println("Executing and waiting for charmap");
charmapStr = "c:\\windows\\system32\\charmap.exe";
} else {
System.out.println("Executing and waiting for firefox");
charmapStr = "firefox http://www.google.com";
}
Process cm = runtime.exec(charmapStr);
System.out.println("Exit value: " + cm.waitFor());
}
}

View File

@ -29,4 +29,4 @@ jni/build/libuntrusted_corda_sgx.so: jni/build/Makefile ../../verify-enclave/bui
.PHONY: clean .PHONY: clean
clean: clean:
rm -rf {standalone,common,enclave,jni}/build $(RM) -r {standalone,common,enclave,jni}/build

View File

@ -40,9 +40,9 @@ dependencies {
// TODO think about this. // TODO think about this.
compile project(':node-api') compile project(':node-api')
compile "org.jetbrains.kotlin:kotlin-stdlib:$kotlin_version" compile "org.jetbrains.kotlin:kotlin-stdlib-jre8:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version" compile "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
compile "org.jetbrains.kotlin:kotlin-test:$kotlin_version" testCompile "org.jetbrains.kotlin:kotlin-test:$kotlin_version"
testCompile project(':test-utils') testCompile project(':test-utils')
} }

View File

@ -3,31 +3,12 @@
package com.r3.enclaves.txverify package com.r3.enclaves.txverify
import com.esotericsoftware.minlog.Log import com.esotericsoftware.minlog.Log
import net.corda.core.contracts.Attachment
import net.corda.core.contracts.StateRef
import net.corda.core.contracts.TransactionResolutionException
import net.corda.core.contracts.TransactionState
import net.corda.core.crypto.SecureHash
import net.corda.core.identity.AbstractParty
import net.corda.core.identity.AnonymousParty
import net.corda.core.identity.Party
import net.corda.core.identity.PartyAndCertificate
import net.corda.core.node.ServicesForResolution
import net.corda.core.node.services.AttachmentStorage
import net.corda.core.node.services.AttachmentsStorageService
import net.corda.core.node.services.IdentityService
import net.corda.core.serialization.CordaSerializable import net.corda.core.serialization.CordaSerializable
import net.corda.core.serialization.SerializedBytes import net.corda.core.serialization.SerializedBytes
import net.corda.core.serialization.createTestKryo import net.corda.core.serialization.createTestKryo
import net.corda.core.serialization.deserialize import net.corda.core.serialization.deserialize
import net.corda.core.transactions.WireTransaction import net.corda.core.transactions.WireTransaction
import org.bouncycastle.asn1.x500.X500Name
import java.io.File import java.io.File
import java.io.InputStream
import java.nio.file.Path
import java.security.PublicKey
import java.security.cert.CertPath
import java.security.cert.X509Certificate
// This file implements the functionality of the SGX transaction verification enclave. // This file implements the functionality of the SGX transaction verification enclave.