Skip to content

Commit d1bef49

Browse files
Merge pull request #1642 from matthiasblaesing/android-fix-16k
Fix calls to jnidispatch on Android with 16KB page size
2 parents 3befd7f + e62279f commit d1bef49

File tree

11 files changed

+29
-13
lines changed

11 files changed

+29
-13
lines changed

CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ Features
1111

1212
Bug Fixes
1313
---------
14+
* [#1618](https://github.com/java-native-access/jna/issues/1618): Fix calls to jnidispatch on Android with 16KB page size - [@Thomyrock](https://github.com/Thomyrock)
1415

1516
Release 5.15.0
1617
==============

common.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
<!-- jnidispatch library release version -->
2323
<property name="jni.major" value="7"/>
2424
<property name="jni.minor" value="0"/>
25-
<property name="jni.revision" value="2"/>
25+
<property name="jni.revision" value="3"/>
2626
<property name="jni.build" value="0"/> <!--${build.number}-->
2727
<property name="jni.version" value="${jni.major}.${jni.minor}.${jni.revision}"/>
2828
<property name="jni.md5" value="5fb98531302accd485c534c452dd952a"/>

contrib/platform/test/com/sun/jna/platform/linux/UdevTest.java

+25-10
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
import com.sun.jna.platform.linux.Udev.UdevDevice;
3030
import com.sun.jna.platform.linux.Udev.UdevEnumerate;
3131
import com.sun.jna.platform.linux.Udev.UdevListEntry;
32+
import java.util.regex.Matcher;
33+
import java.util.regex.Pattern;
3234

3335
import junit.framework.TestCase;
3436

@@ -37,6 +39,8 @@
3739
*/
3840
public class UdevTest extends TestCase {
3941

42+
private static final Pattern SCSI_DISK_PATTERN = Pattern.compile(".*/sd[a-z](\\d+)$");
43+
4044
@Test
4145
public void testEnumerateDevices() {
4246
// Start with the context object
@@ -74,29 +78,40 @@ public void testEnumerateDevices() {
7478
// No additional reference is acquired from getParent
7579
if (parent != null && parent2 != null) {
7680
// Devnode should match same parent without restricting to block and disk
77-
assertEquals("Partition parent should match with and without filter",
81+
assertEquals(String.format(
82+
"Partition parent should match with and without filter (%s)",
83+
devnode
84+
),
7885
parent.getDevnode(), parent2.getDevnode());
7986
// Save the size and major
8087
parentSize = parent.getSysattrValue("size");
8188
parentMajor = parent.getPropertyValue("MAJOR");
8289
}
8390
}
8491
String size = device.getSysattrValue("size");
85-
assertTrue("Size must be nonnegative", 0 <= Long.parseLong(size));
92+
assertTrue(String.format("Size must be nonnegative (%s)", devnode), 0 <= Long.parseLong(size));
8693
if (parentSize != null) {
87-
assertTrue("Partition can't be bigger than its disk",
94+
assertTrue(String.format("Partition can't be bigger than its disk (%s)", devnode),
8895
Long.parseLong(size) <= Long.parseLong(parentSize));
8996
}
9097
String major = device.getPropertyValue("MAJOR");
91-
assertTrue("Major value must be nonnegative", 0 <= Long.parseLong(major));
98+
assertTrue(String.format("Major value must be nonnegative (%s)", devnode), 0 <= Long.parseLong(major));
9299
if (parentMajor != null) {
93-
assertEquals("Partition and its parent disk should have same major number", major,
94-
parentMajor);
100+
// For scsi disks only the first 15 Partitions have the
101+
// same major as their disk
102+
Matcher scsiMatcher = SCSI_DISK_PATTERN.matcher(devnode);
103+
boolean scsiDiskDynamicMinor = scsiMatcher.matches() && Integer.parseInt(scsiMatcher.group(1)) > 15;
104+
if(! scsiDiskDynamicMinor) {
105+
assertEquals(
106+
String.format("Partition and its parent disk should have same major number (%s)", devnode),
107+
major, parentMajor
108+
);
109+
}
95110
}
96-
assertEquals("DevType mismatch", devType, device.getDevtype());
97-
assertEquals("Subsystem mismatch", "block", device.getSubsystem());
98-
assertEquals("Syspath mismatch", syspath, device.getSyspath());
99-
assertTrue("Syspath should end with name", syspath.endsWith(device.getSysname()));
111+
assertEquals(String.format("DevType mismatch (%s)", devnode), devType, device.getDevtype());
112+
assertEquals(String.format("Subsystem mismatch (%s)", devnode), "block", device.getSubsystem());
113+
assertEquals(String.format("Syspath mismatch (%s)", devnode), syspath, device.getSyspath());
114+
assertTrue(String.format("Syspath should end with name (%s)", devnode), syspath.endsWith(device.getSysname()));
100115
}
101116
} finally {
102117
// Release the reference and iterate to the next device

lib/native/android-aarch64.jar

3 Bytes
Binary file not shown.

lib/native/android-arm.jar

71 Bytes
Binary file not shown.

lib/native/android-armv7.jar

55 Bytes
Binary file not shown.

lib/native/android-mips.jar

-207 Bytes
Binary file not shown.

lib/native/android-mips64.jar

-43 Bytes
Binary file not shown.

lib/native/android-x86-64.jar

118 Bytes
Binary file not shown.

lib/native/android-x86.jar

59 Bytes
Binary file not shown.

native/Makefile

+2-2
Original file line numberDiff line numberDiff line change
@@ -176,12 +176,12 @@ CPP=$(PREFIX)cpp
176176
LD=$(CC)
177177
RANLIB=$(PREFIX)ranlib
178178
STRIP=$(PREFIX)strip -x
179-
CDEFINES=-DFFI_STATIC_BUILD -DNO_JAWT -DNO_WEAK_GLOBALS -DFFI_MMAP_EXEC_WRIT=1 -DFFI_MMAP_EXEC_SELINUX=0
179+
CDEFINES=-DFFI_STATIC_BUILD -DNO_JAWT -DNO_WEAK_GLOBALS -DFFI_MMAP_EXEC_WRIT=1 -DFFI_MMAP_EXEC_SELINUX=0 -Dmalloc_getpagesize='getpagesize()'
180180
COPT+=-fpic -ffunction-sections -funwind-tables -fno-short-enums
181181
JAVA_INCLUDES=
182182
CINCLUDES+=-I"$(NDK_PLATFORM)/arch-$(AARCH)/usr/include" # -I/usr/include
183183
LIBS=-nostdlib -L"$(NDK_PLATFORM)/arch-$(AARCH)$(ALIBDIR)/" -lgcc -lc -ldl -lm
184-
LDFLAGS+=-Wl,-shared,-Bsymbolic -Wl,--build-id=sha1
184+
LDFLAGS+=-Wl,-shared,-Bsymbolic -Wl,--build-id=sha1 -Wl,-z,max-page-size=16384
185185
FFI_ENV=CPP="$(CPP)" CC="$(CC)" CFLAGS="$(COPT) $(CDEBUG) $(CINCLUDES)" CPPFLAGS="$(CDEFINES) $(CINCLUDES)" LIBS="$(LIBS)" RANLIB="$(RANLIB)"
186186
FFI_CONFIG=--enable-static --disable-shared --with-pic=yes --host=$(HOST)
187187
endif

0 commit comments

Comments
 (0)