Only load native transport if running architecture match the compiled library architecture.
Motivation: We should only try to load the native artifacts if the architecture we are currently running on is the same as the one the native libraries were compiled for. Modifications: Include architecture in native lib name and append the current arch when trying to load these. This will fail then if its not the same as the arch of the compiled arch. Result: Fixes [#7150].
This commit is contained in:
parent
379ac890f4
commit
0fffc844d6
@ -92,6 +92,8 @@ public final class PlatformDependent {
|
||||
private static final File TMPDIR = tmpdir0();
|
||||
|
||||
private static final int BIT_MODE = bitMode0();
|
||||
private static final String NORMALIZED_ARCH = normalizeArch(SystemPropertyUtil.get("os.arch", ""));
|
||||
private static final String NORMALIZED_OS = normalizeOs(SystemPropertyUtil.get("os.name", ""));
|
||||
|
||||
private static final int ADDRESS_SIZE = addressSize0();
|
||||
private static final boolean USE_DIRECT_BUFFER_NO_CLEANER;
|
||||
@ -1238,6 +1240,99 @@ public final class PlatformDependent {
|
||||
}
|
||||
}
|
||||
|
||||
public static String normalizedArch() {
|
||||
return NORMALIZED_ARCH;
|
||||
}
|
||||
|
||||
public static String normalizedOs() {
|
||||
return NORMALIZED_OS;
|
||||
}
|
||||
|
||||
private static String normalize(String value) {
|
||||
return value.toLowerCase(Locale.US).replaceAll("[^a-z0-9]+", "");
|
||||
}
|
||||
|
||||
private static String normalizeArch(String value) {
|
||||
value = normalize(value);
|
||||
if (value.matches("^(x8664|amd64|ia32e|em64t|x64)$")) {
|
||||
return "x86_64";
|
||||
}
|
||||
if (value.matches("^(x8632|x86|i[3-6]86|ia32|x32)$")) {
|
||||
return "x86_32";
|
||||
}
|
||||
if (value.matches("^(ia64|itanium64)$")) {
|
||||
return "itanium_64";
|
||||
}
|
||||
if (value.matches("^(sparc|sparc32)$")) {
|
||||
return "sparc_32";
|
||||
}
|
||||
if (value.matches("^(sparcv9|sparc64)$")) {
|
||||
return "sparc_64";
|
||||
}
|
||||
if (value.matches("^(arm|arm32)$")) {
|
||||
return "arm_32";
|
||||
}
|
||||
if ("aarch64".equals(value)) {
|
||||
return "aarch_64";
|
||||
}
|
||||
if (value.matches("^(ppc|ppc32)$")) {
|
||||
return "ppc_32";
|
||||
}
|
||||
if ("ppc64".equals(value)) {
|
||||
return "ppc_64";
|
||||
}
|
||||
if ("ppc64le".equals(value)) {
|
||||
return "ppcle_64";
|
||||
}
|
||||
if ("s390".equals(value)) {
|
||||
return "s390_32";
|
||||
}
|
||||
if ("s390x".equals(value)) {
|
||||
return "s390_64";
|
||||
}
|
||||
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
private static String normalizeOs(String value) {
|
||||
value = normalize(value);
|
||||
if (value.startsWith("aix")) {
|
||||
return "aix";
|
||||
}
|
||||
if (value.startsWith("hpux")) {
|
||||
return "hpux";
|
||||
}
|
||||
if (value.startsWith("os400")) {
|
||||
// Avoid the names such as os4000
|
||||
if (value.length() <= 5 || !Character.isDigit(value.charAt(5))) {
|
||||
return "os400";
|
||||
}
|
||||
}
|
||||
if (value.startsWith("linux")) {
|
||||
return "linux";
|
||||
}
|
||||
if (value.startsWith("macosx") || value.startsWith("osx")) {
|
||||
return "osx";
|
||||
}
|
||||
if (value.startsWith("freebsd")) {
|
||||
return "freebsd";
|
||||
}
|
||||
if (value.startsWith("openbsd")) {
|
||||
return "openbsd";
|
||||
}
|
||||
if (value.startsWith("netbsd")) {
|
||||
return "netbsd";
|
||||
}
|
||||
if (value.startsWith("solaris") || value.startsWith("sunos")) {
|
||||
return "sunos";
|
||||
}
|
||||
if (value.startsWith("windows")) {
|
||||
return "windows";
|
||||
}
|
||||
|
||||
return "unknown";
|
||||
}
|
||||
|
||||
private static final class AtomicLongCounter extends AtomicLong implements LongCounter {
|
||||
private static final long serialVersionUID = 4074772784610639305L;
|
||||
|
||||
|
@ -25,6 +25,7 @@ import io.netty.internal.tcnative.SSLContext;
|
||||
import io.netty.util.ReferenceCountUtil;
|
||||
import io.netty.util.ReferenceCounted;
|
||||
import io.netty.util.internal.NativeLibraryLoader;
|
||||
import io.netty.util.internal.PlatformDependent;
|
||||
import io.netty.util.internal.SystemPropertyUtil;
|
||||
import io.netty.util.internal.logging.InternalLogger;
|
||||
import io.netty.util.internal.logging.InternalLoggerFactory;
|
||||
@ -36,7 +37,6 @@ import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Set;
|
||||
|
||||
import static io.netty.handler.ssl.SslUtils.DEFAULT_CIPHER_SUITES;
|
||||
@ -56,8 +56,6 @@ import static io.netty.handler.ssl.SslUtils.PROTOCOL_TLS_V1_2;
|
||||
public final class OpenSsl {
|
||||
|
||||
private static final InternalLogger logger = InternalLoggerFactory.getInstance(OpenSsl.class);
|
||||
private static final String LINUX = "linux";
|
||||
private static final String UNKNOWN = "unknown";
|
||||
private static final Throwable UNAVAILABILITY_CAUSE;
|
||||
|
||||
static final List<String> DEFAULT_CIPHERS;
|
||||
@ -404,14 +402,14 @@ public final class OpenSsl {
|
||||
private OpenSsl() { }
|
||||
|
||||
private static void loadTcNative() throws Exception {
|
||||
String os = normalizeOs(SystemPropertyUtil.get("os.name", ""));
|
||||
String arch = normalizeArch(SystemPropertyUtil.get("os.arch", ""));
|
||||
String os = PlatformDependent.normalizedOs();
|
||||
String arch = PlatformDependent.normalizedArch();
|
||||
|
||||
Set<String> libNames = new LinkedHashSet<String>(4);
|
||||
// First, try loading the platform-specific library. Platform-specific
|
||||
// libraries will be available if using a tcnative uber jar.
|
||||
libNames.add("netty_tcnative_" + os + '_' + arch);
|
||||
if (LINUX.equalsIgnoreCase(os)) {
|
||||
if ("linux".equalsIgnoreCase(os)) {
|
||||
// Fedora SSL lib so naming (libssl.so.10 vs libssl.so.1.0.0)..
|
||||
libNames.add("netty_tcnative_" + os + '_' + arch + "_fedora");
|
||||
}
|
||||
@ -426,91 +424,6 @@ public final class OpenSsl {
|
||||
return Library.initialize();
|
||||
}
|
||||
|
||||
private static String normalizeOs(String value) {
|
||||
value = normalize(value);
|
||||
if (value.startsWith("aix")) {
|
||||
return "aix";
|
||||
}
|
||||
if (value.startsWith("hpux")) {
|
||||
return "hpux";
|
||||
}
|
||||
if (value.startsWith("os400")) {
|
||||
// Avoid the names such as os4000
|
||||
if (value.length() <= 5 || !Character.isDigit(value.charAt(5))) {
|
||||
return "os400";
|
||||
}
|
||||
}
|
||||
if (value.startsWith(LINUX)) {
|
||||
return LINUX;
|
||||
}
|
||||
if (value.startsWith("macosx") || value.startsWith("osx")) {
|
||||
return "osx";
|
||||
}
|
||||
if (value.startsWith("freebsd")) {
|
||||
return "freebsd";
|
||||
}
|
||||
if (value.startsWith("openbsd")) {
|
||||
return "openbsd";
|
||||
}
|
||||
if (value.startsWith("netbsd")) {
|
||||
return "netbsd";
|
||||
}
|
||||
if (value.startsWith("solaris") || value.startsWith("sunos")) {
|
||||
return "sunos";
|
||||
}
|
||||
if (value.startsWith("windows")) {
|
||||
return "windows";
|
||||
}
|
||||
|
||||
return UNKNOWN;
|
||||
}
|
||||
|
||||
private static String normalizeArch(String value) {
|
||||
value = normalize(value);
|
||||
if (value.matches("^(x8664|amd64|ia32e|em64t|x64)$")) {
|
||||
return "x86_64";
|
||||
}
|
||||
if (value.matches("^(x8632|x86|i[3-6]86|ia32|x32)$")) {
|
||||
return "x86_32";
|
||||
}
|
||||
if (value.matches("^(ia64|itanium64)$")) {
|
||||
return "itanium_64";
|
||||
}
|
||||
if (value.matches("^(sparc|sparc32)$")) {
|
||||
return "sparc_32";
|
||||
}
|
||||
if (value.matches("^(sparcv9|sparc64)$")) {
|
||||
return "sparc_64";
|
||||
}
|
||||
if (value.matches("^(arm|arm32)$")) {
|
||||
return "arm_32";
|
||||
}
|
||||
if ("aarch64".equals(value)) {
|
||||
return "aarch_64";
|
||||
}
|
||||
if (value.matches("^(ppc|ppc32)$")) {
|
||||
return "ppc_32";
|
||||
}
|
||||
if ("ppc64".equals(value)) {
|
||||
return "ppc_64";
|
||||
}
|
||||
if ("ppc64le".equals(value)) {
|
||||
return "ppcle_64";
|
||||
}
|
||||
if ("s390".equals(value)) {
|
||||
return "s390_32";
|
||||
}
|
||||
if ("s390x".equals(value)) {
|
||||
return "s390_64";
|
||||
}
|
||||
|
||||
return UNKNOWN;
|
||||
}
|
||||
|
||||
private static String normalize(String value) {
|
||||
return value.toLowerCase(Locale.US).replaceAll("[^a-z0-9]+", "");
|
||||
}
|
||||
|
||||
static void releaseIfNeeded(ReferenceCounted counted) {
|
||||
if (counted.refCnt() > 0) {
|
||||
ReferenceCountUtil.safeRelease(counted);
|
||||
|
@ -144,7 +144,7 @@
|
||||
<execution>
|
||||
<id>build-native-lib</id>
|
||||
<configuration>
|
||||
<name>netty_transport_native_epoll</name>
|
||||
<name>netty_transport_native_epoll_${os.detected.arch}</name>
|
||||
<nativeSourceDirectory>${project.basedir}/src/main/c</nativeSourceDirectory>
|
||||
<libDirectory>${project.build.outputDirectory}</libDirectory>
|
||||
<!-- We use Maven's artifact classifier instead.
|
||||
@ -179,7 +179,7 @@
|
||||
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
|
||||
</manifest>
|
||||
<manifestEntries>
|
||||
<Bundle-NativeCode>META-INF/native/libnetty_transport_native_epoll.so; osname=linux; processor=x86_64,*</Bundle-NativeCode>
|
||||
<Bundle-NativeCode>META-INF/native/libnetty_transport_native_epoll_${os.detected.arch}.so; osname=linux; processor=${os.detected.arch},*</Bundle-NativeCode>
|
||||
</manifestEntries>
|
||||
<index>true</index>
|
||||
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
|
||||
|
@ -196,7 +196,8 @@ public final class Native {
|
||||
if (!name.startsWith("linux")) {
|
||||
throw new IllegalStateException("Only supported on Linux");
|
||||
}
|
||||
NativeLibraryLoader.load("netty_transport_native_epoll", PlatformDependent.getClassLoader(Native.class));
|
||||
NativeLibraryLoader.load("netty_transport_native_epoll_" + PlatformDependent.normalizedArch(),
|
||||
PlatformDependent.getClassLoader(Native.class));
|
||||
}
|
||||
|
||||
private Native() {
|
||||
|
@ -70,7 +70,7 @@
|
||||
<execution>
|
||||
<id>build-native-lib</id>
|
||||
<configuration>
|
||||
<name>netty_transport_native_kqueue</name>
|
||||
<name>netty_transport_native_kqueue_${os.detected.arch}</name>
|
||||
<nativeSourceDirectory>${project.basedir}/src/main/c</nativeSourceDirectory>
|
||||
<libDirectory>${project.build.outputDirectory}</libDirectory>
|
||||
<!-- We use Maven's artifact classifier instead.
|
||||
@ -110,7 +110,7 @@
|
||||
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
|
||||
</manifest>
|
||||
<manifestEntries>
|
||||
<Bundle-NativeCode>META-INF/native/libnetty_transport_native_kqueue.jnilib; osname=darwin, processor=x86_64"</Bundle-NativeCode>
|
||||
<Bundle-NativeCode>META-INF/native/libnetty_transport_native_kqueue_${os.detected.arch}.jnilib; osname=darwin, processor=${os.detected.arch}"</Bundle-NativeCode>
|
||||
</manifestEntries>
|
||||
<index>true</index>
|
||||
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
|
||||
@ -179,7 +179,7 @@
|
||||
<execution>
|
||||
<id>build-native-lib</id>
|
||||
<configuration>
|
||||
<name>netty_transport_native_kqueue</name>
|
||||
<name>netty_transport_native_kqueue_${os.detected.arch}</name>
|
||||
<nativeSourceDirectory>${project.basedir}/src/main/c</nativeSourceDirectory>
|
||||
<libDirectory>${project.build.outputDirectory}</libDirectory>
|
||||
<!-- We use Maven's artifact classifier instead.
|
||||
@ -217,7 +217,7 @@
|
||||
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
|
||||
</manifest>
|
||||
<manifestEntries>
|
||||
<Bundle-NativeCode>META-INF/native/libnetty_transport_native_kqueue.jnilib; osname=darwin, processor=x86_64"</Bundle-NativeCode>
|
||||
<Bundle-NativeCode>META-INF/native/libnetty_transport_native_kqueue_${os.detected.arch}.jnilib; osname=darwin, processor=${os.detected.arch}"</Bundle-NativeCode>
|
||||
</manifestEntries>
|
||||
<index>true</index>
|
||||
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
|
||||
@ -286,7 +286,7 @@
|
||||
<execution>
|
||||
<id>build-native-lib</id>
|
||||
<configuration>
|
||||
<name>netty_transport_native_kqueue</name>
|
||||
<name>netty_transport_native_kqueue_${os.detected.arch}</name>
|
||||
<nativeSourceDirectory>${project.basedir}/src/main/c</nativeSourceDirectory>
|
||||
<libDirectory>${project.build.outputDirectory}</libDirectory>
|
||||
<!-- We use Maven's artifact classifier instead.
|
||||
@ -324,7 +324,7 @@
|
||||
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
|
||||
</manifest>
|
||||
<manifestEntries>
|
||||
<Bundle-NativeCode>META-INF/native/libnetty_transport_native_kqueue.jnilib; osname=darwin, processor=x86_64"</Bundle-NativeCode>
|
||||
<Bundle-NativeCode>META-INF/native/libnetty_transport_native_kqueue_${os.detected.arch}.jnilib; osname=darwin, processor=${os.detected.arch}"</Bundle-NativeCode>
|
||||
</manifestEntries>
|
||||
<index>true</index>
|
||||
<manifestFile>${project.build.outputDirectory}/META-INF/MANIFEST.MF</manifestFile>
|
||||
|
@ -111,7 +111,8 @@ final class Native {
|
||||
if (!name.startsWith("mac") && !name.contains("bsd") && !name.startsWith("darwin")) {
|
||||
throw new IllegalStateException("Only supported on BSD");
|
||||
}
|
||||
NativeLibraryLoader.load("netty_transport_native_kqueue", PlatformDependent.getClassLoader(Native.class));
|
||||
NativeLibraryLoader.load("netty_transport_native_kqueue_" + PlatformDependent.normalizedArch(),
|
||||
PlatformDependent.getClassLoader(Native.class));
|
||||
}
|
||||
|
||||
private Native() {
|
||||
|
Loading…
Reference in New Issue
Block a user