From 350c0c18bb5d61bd4d4784880dfb470ee7a75bd9 Mon Sep 17 00:00:00 2001 From: panxuefeng Date: Wed, 25 May 2022 11:13:00 +0800 Subject: [PATCH] Support Loongarch64 Co-Authored-By: Ao Qi --- build.xml | 6 ++++++ src/com/sun/jna/Native.java | 2 +- src/com/sun/jna/NativeLibrary.java | 3 +++ src/com/sun/jna/Platform.java | 5 +++++ src/com/sun/jna/Structure.java | 4 ++-- 5 files changed, 17 insertions(+), 3 deletions(-) diff --git a/build.xml b/build.xml index b81b9d7584..31a053fe5a 100644 --- a/build.xml +++ b/build.xml @@ -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, @@ -638,6 +640,9 @@ osname=macosx;processor=aarch64 + @@ -851,6 +856,7 @@ osname=macosx;processor=aarch64 + diff --git a/src/com/sun/jna/Native.java b/src/com/sun/jna/Native.java index b832d4052f..e3c3d8ebef 100644 --- a/src/com/sun/jna/Native.java +++ b/src/com/sun/jna/Native.java @@ -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; diff --git a/src/com/sun/jna/NativeLibrary.java b/src/com/sun/jna/NativeLibrary.java index c68e773d1d..63d0b8a24d 100644 --- a/src/com/sun/jna/NativeLibrary.java +++ b/src/com/sun/jna/NativeLibrary.java @@ -988,6 +988,9 @@ else if (Platform.isARM()) { else if (Platform.ARCH.equals("mips64el")) { libc = "-gnuabi64"; } + else if (Platform.ARCH.equals("loongarch64")) { + libc = "-gnuabi64"; // TODO: not sure + } return cpu + kernel + libc; } diff --git a/src/com/sun/jna/Platform.java b/src/com/sun/jna/Platform.java index 7ee19e4a5b..ac1395e95d 100644 --- a/src/com/sun/jna/Platform.java +++ b/src/com/sun/jna/Platform.java @@ -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; @@ -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)) { diff --git a/src/com/sun/jna/Structure.java b/src/com/sun/jna/Structure.java index b2457f69d7..39d3da0efa 100644 --- a/src/com/sun/jna/Structure.java +++ b/src/com/sun/jna/Structure.java @@ -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 @@ -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) {