xxDark / SSVM

Java VM running on a JVM
MIT License
166 stars 17 forks source link

Feature/nio #23

Open Col-E opened 1 year ago

Col-E commented 1 year ago

Current failure VM trace:

jdk/internal/loader/URLClassPath$JarLoader$1.run()Ljava/lang/Void;
jdk/internal/util/jar/JarIndex.getJarIndex(Ljava/util/jar/JarFile;)Ljdk/internal/util/jar/JarIndex;
java/util/jar/JarFile.getJarEntry(Ljava/lang/String;)Ljava/util/jar/JarEntry;
java/util/jar/JarFile.getEntry(Ljava/lang/String;)Ljava/util/zip/ZipEntry;
java/util/jar/JarFile.isMultiRelease()Z
java/util/jar/JarFile.checkForSpecialAttributes()V
java/util/jar/JarFile.getBytes(Ljava/util/zip/ZipEntry;)[B
java/util/zip/ZipFile.getInputStream(Ljava/util/zip/ZipEntry;)Ljava/io/InputStream;
java/util/zip/ZipFile$ZipFileInflaterInputStream.<init>(Ljava/util/zip/ZipFile;Ljava/util/zip/ZipFile$ZipFileInputStream;Ljava/util/zip/ZipFile$CleanableResource;I)V
java/util/zip/ZipFile$CleanableResource.getInflater()Ljava/util/zip/Inflater;
java/util/zip/Inflater.<init>(Z)V
java/util/zip/Inflater.init(Z)J

The InflaterNatives class only handles initIDs. We either need to implement those, or hook Zip files in a different way on JDK 9+

Col-E commented 1 year ago

Went with a different approach for hooking ZipFile handles on JDK 9+

Then I hit a wall with Inflater natives still in some jar file handling... so to work around that I made a getInputStream invoker. Its not the greatest solution, but it lets me focus on the actual NIO integration, as now the VM stacktrace is finally hitting something relevant:

dev/xdark/ssvm/dummy/FileToString.readReadmePath()Ljava/lang/String;
dev/xdark/ssvm/dummy/FileToString.read(Ljava/nio/file/Path;)Ljava/lang/String;
java/nio/file/Files.readAllBytes(Ljava/nio/file/Path;)[B
java/nio/file/Files.newByteChannel(Ljava/nio/file/Path;[Ljava/nio/file/OpenOption;)Ljava/nio/channels/SeekableByteChannel;
java/nio/file/Files.newByteChannel(Ljava/nio/file/Path;Ljava/util/Set;[Ljava/nio/file/attribute/FileAttribute;)Ljava/nio/channels/SeekableByteChannel;
sun/nio/fs/WindowsFileSystemProvider.newByteChannel(Ljava/nio/file/Path;Ljava/util/Set;[Ljava/nio/file/attribute/FileAttribute;)Ljava/nio/channels/SeekableByteChannel;
sun/nio/fs/WindowsChannelFactory.newFileChannel(Ljava/lang/String;Ljava/lang/String;Ljava/util/Set;J)Ljava/nio/channels/FileChannel;
sun/nio/fs/WindowsChannelFactory.open(Ljava/lang/String;Ljava/lang/String;Lsun/nio/fs/WindowsChannelFactory$Flags;J)Ljava/io/FileDescriptor;
sun/nio/fs/WindowsNativeDispatcher.CreateFile(Ljava/lang/String;IIJII)J
sun/nio/fs/WindowsNativeDispatcher.CreateFile0(JIIJII)J <--- Not yet implemented