Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Loongarch64 #1440

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Expand Up @@ -9,6 +9,7 @@ Features
--------
* [#1433](https://github.com/java-native-access/jna/pull/1433): Add `CFEqual`, `CFDictionaryRef.ByReference`, `CFStringRef.ByReference` to `c.s.j.p.mac.CoreFoundation` - [@shalupov](https://github.com/shalupov)
* [#978](https://github.com/java-native-access/jna/issues/978): Remove use of finalizers in JNA and improve concurrency for `Memory`, `CallbackReference` and `NativeLibrary` - [@matthiasblaesing](https://github.com/matthiasblaesing).
* [#1440](https://github.com/java-native-access/jna/pull/1440): Support for LoongArch64 - [@Panxuefeng-loongson](https://github.com/Panxuefeng-loongson).

Bug Fixes
---------
Expand Down
6 changes: 6 additions & 0 deletions build.xml
Expand Up @@ -529,6 +529,8 @@ com/sun/jna/linux-mips64el/libjnidispatch.so;
processor=mips64el;osname=linux,
com/sun/jna/linux-s390x/libjnidispatch.so;
processor=S390x;osname=linux,
com/sun/jna/linux-loongarch64/libjnidispatch.so;
processor=loongarch64;osname=linux,
com/sun/jna/freebsd-x86/libjnidispatch.so;
processor=x86;osname=freebsd,
Expand Down Expand Up @@ -638,6 +640,9 @@ osname=macosx;processor=aarch64
<zipfileset src="${lib.native}/linux-mips64el.jar"
includes="*jnidispatch*"
prefix="com/sun/jna/linux-mips64el"/>
<zipfileset src="${lib.native}/linux-loongarch64.jar"
includes="*jnidispatch*"
prefix="com/sun/jna/linux-loongarch64"/>
<zipfileset src="${lib.native}/linux-s390x.jar"
includes="*jnidispatch*"
prefix="com/sun/jna/linux-s390x"/>
Expand Down Expand Up @@ -851,6 +856,7 @@ osname=macosx;processor=aarch64
<copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/linux-ppc64le.jar" overwrite="true"/>
<copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/linux-sparcv9.jar" overwrite="true"/>
<copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/linux-mips64el.jar" overwrite="true"/>
<copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/linux-loongarch64.jar" overwrite="true"/>
<copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/linux-s390x.jar" overwrite="true"/>
<copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/linux-riscv64.jar" overwrite="true"/>
<copy file="${lib.native}/out-of-date.jar" tofile="${lib.native}/freebsd-x86.jar" overwrite="true"/>
Expand Down
Binary file added lib/native/linux-loongarch64.jar
Binary file not shown.
2 changes: 1 addition & 1 deletion src/com/sun/jna/Native.java
Expand Up @@ -250,7 +250,7 @@ static boolean isCompatibleVersion(String expectedVersion, String nativeVersion)
setProtected(true);
}
MAX_ALIGNMENT = Platform.isSPARC() || Platform.isWindows()
|| (Platform.isLinux() && (Platform.isARM() || Platform.isPPC() || Platform.isMIPS()))
|| (Platform.isLinux() && (Platform.isARM() || Platform.isPPC() || Platform.isMIPS() || Platform.isLoongArch()))
|| Platform.isAIX()
|| (Platform.isAndroid() && !Platform.isIntel())
? 8 : LONG_SIZE;
Expand Down
5 changes: 5 additions & 0 deletions src/com/sun/jna/Platform.java
Expand Up @@ -195,6 +195,7 @@ public static final boolean is64Bit() {
|| "ppc64".equals(ARCH) || "ppc64le".equals(ARCH)
|| "sparcv9".equals(ARCH)
|| "mips64".equals(ARCH) || "mips64el".equals(ARCH)
|| "loongarch64".equals(ARCH)
|| "amd64".equals(ARCH)
|| "aarch64".equals(ARCH)) {
return true;
Expand Down Expand Up @@ -234,6 +235,10 @@ public static final boolean isMIPS() {
return false;
}

public static final boolean isLoongArch() {
return ARCH.startsWith("loongarch");
}

static String getCanonicalArchitecture(String arch, int platform) {
arch = arch.toLowerCase().trim();
if ("powerpc".equals(arch)) {
Expand Down
4 changes: 2 additions & 2 deletions src/com/sun/jna/Structure.java
Expand Up @@ -2081,7 +2081,7 @@ public FFIType(Structure ref) {
}
}
if ((Platform.isIntel() && Platform.is64Bit() && !Platform.isWindows())
|| Platform.isARM()) {
|| Platform.isARM() || Platform.isLoongArch()) {
// System V x86-64 ABI requires, that in a union aggregate,
// that contains Integer and Double members, the parameters
// must be passed in the integer registers. I.e. in the case
Expand All @@ -2091,7 +2091,7 @@ public FFIType(Structure ref) {
// passing method would be used.
//
// It was observed, that the same behaviour is visible on
// arm/aarch64.
// arm/aarch64/loongarch64.
if(hasInteger && isFloatType(unionType)) {
unionType = new FFIType(unionType);
if(unionType.size.intValue() == 4) {
Expand Down