United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-7114611 : (fs) DirectoryStream fails with SIGBUS on some embedded platforms, dirent alignment

Details
Type:
Bug
Submit Date:
2011-11-22
Status:
Closed
Updated Date:
2012-05-07
Project Name:
JDK
Resolved Date:
2012-05-07
Component:
core-libs
OS:
generic
Sub-Component:
java.nio
CPU:
generic
Priority:
P3
Resolution:
Fixed
Affected Versions:
7u2
Fixed Versions:

Related Reports
Backport:
Relates:

Sub Tasks

Description
Several JCK tests crash with SIGBUS in readdir64_r. The crash only happens when /proc/cpu/alignment is set not to ignore alignment errors (i.e. echo 5 > /proc/cpu/alignment). See Comments for more details.

# A fatal error has been detected by the Java Runtime Environment:
#
#  SIGBUS (0x7) at pc=0x400fd7cc, pid=3863, tid=1081996400
#
# JRE version: 7.0_02-b12
# Java VM: Java HotSpot(TM) Client VM (22.0-b09 mixed mode, sharing linux-arm )
# Problematic frame:
# C  [libc.so.6+0x907cc]  readdir64_r+0xe0

Stack: [0x40790000,0x407e0000],  sp=0x407dd2d8,  free space=308k
Native frames: (J=compiled Java code, j=interpreted, Vv=VM code, C=native code)
C  [libc.so.6+0x907cc]  readdir64_r+0xe0

Java frames: (J=compiled Java code, j=interpreted, Vv=VM code)
j  sun.nio.fs.UnixNativeDispatcher.readdir(J)[B+0
j  sun.nio.fs.UnixDirectoryStream$UnixDirectoryIterator.readNextEntry()Ljava/nio/file/Path;+52
j  sun.nio.fs.UnixDirectoryStream$UnixDirectoryIterator.hasNext()Z+16
j  javasoft.sqe.tests.api.java.nio.file.Files.CpMvDelTests$2.runTest()Ljavasoft/sqe/javatest/Status;+212
j  javasoft.sqe.tests.api.java.nio.Nio2TestCase$Single.runTestSafely()Ljavasoft/sqe/javatest/Status;+1
j  javasoft.sqe.tests.api.java.nio.Nio2TestCase$Single.runTestWithPerms(Z[Ljava/security/Permission;)Ljavasoft/sqe/javatest/Status;+196
j  javasoft.sqe.tests.api.java.nio.Nio2TestCase$Single.runTestWithAllPermsGranted()Ljavasoft/sqe/javatest/Status;+6
j  javasoft.sqe.tests.api.java.nio.file.Files.CpMvDelTests.copy_DirDefault()Ljavasoft/sqe/javatest/Status;+101
v  ~StubRoutines::call_stub
j  sun.reflect.NativeMethodAccessorImpl.invoke0(Ljava/lang/reflect/Method;Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;+0
j  sun.reflect.NativeMethodAccessorImpl.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;+87
j  sun.reflect.DelegatingMethodAccessorImpl.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;+6
j  java.lang.reflect.Method.invoke(Ljava/lang/Object;[Ljava/lang/Object;)Ljava/lang/Object;+57
j  javasoft.sqe.javatest.lib.MultiTest.invokeTestCase(Ljava/lang/reflect/Method;)Ljavasoft/sqe/javatest/Status;+8
j  javasoft.sqe.javatest.lib.MultiTest.run([Ljava/lang/String;Ljava/io/PrintWriter;Ljava/io/PrintWriter;)Ljavasoft/sqe/javatest/Status;+152
j  javasoft.sqe.javatest.lib.MultiTest.run([Ljava/lang/String;Ljava/io/PrintStream;Ljava/io/PrintStream;)Ljavasoft/sqe/javatest/Status;+40
j  javasoft.sqe.tests.api.java.nio.file.Files.CpMvDelTests.main([Ljava/lang/String;)V+16
v  ~StubRoutines::call_stub

                                    

Comments
SUGGESTED FIX

struct dirent64* result;
    struct {
        struct dirent64 buf;
        char name_extra[PATH_MAX + 1 - sizeof result->d_name];
    } entry;
    struct dirent64* ptr = &entry.buf;
                                     
2011-11-22
EVALUATION

JNIEXPORT jbyteArray JNICALL
Java_sun_nio_fs_UnixNativeDispatcher_readdir(JNIEnv* env, jclass this, jlong val
ue) {
    char entry[sizeof(struct dirent64) + PATH_MAX + 1];
    struct dirent64* ptr = (struct dirent64*)&entry;

In the above code, ptr may need double-word alignment, but it won't get that from a char[].
                                     
2011-11-22
EVALUATION

Correction, "entry" may need double-word alignment, which is what "ptr" points to.
                                     
2011-11-29
EVALUATION

http://hg.openjdk.java.net/jdk8/tl/jdk/rev/184b9cb4f13a
                                     
2012-02-09



Hardware and Software, Engineered to Work Together