From d573910b7afbef3d872ce8c9ae60c2448e7afc18 Mon Sep 17 00:00:00 2001 From: zzz Date: Mon, 6 Mar 2017 20:44:16 +0000 Subject: [PATCH] CPUID: Fix saving of libjcpuid.jnifile on Macs, was incorrectly saving as libjcpuid.so (tickets #1865, #1900) - Try to load libjcpuid-x86_64-osx.jnilib for 32-bit Macs, because as of 0.9.26 it's a 'fat binary' with 32-bit in it also. This was broken in the 0.9.26 changes. - Improve error logging - Add library search path logging to main() NBI: - Try to load the "none" architecture for x86, even if CPUID loading fails (tickets #1865, #1900) This was broken in the 0.9.26 changes. - Add library search path logging to main() - Comment out unused method --- .../freenet/support/CPUInformation/CPUID.java | 73 ++++++++++++++----- .../src/net/i2p/util/NativeBigInteger.java | 32 +++++++- history.txt | 25 +++++++ .../src/net/i2p/router/RouterVersion.java | 2 +- 4 files changed, 108 insertions(+), 24 deletions(-) diff --git a/core/java/src/freenet/support/CPUInformation/CPUID.java b/core/java/src/freenet/support/CPUInformation/CPUID.java index 3cbee478bf..161cdb64dc 100644 --- a/core/java/src/freenet/support/CPUInformation/CPUID.java +++ b/core/java/src/freenet/support/CPUInformation/CPUID.java @@ -51,11 +51,8 @@ public class CPUID { private static boolean _doLog = System.getProperty("jcpuid.dontLog") == null && I2PAppContext.getGlobalContext().isRouterContext(); - private static final boolean isX86 = System.getProperty("os.arch").contains("86") || - System.getProperty("os.arch").equals("amd64"); + private static final boolean isX86 = SystemVersion.isX86(); private static final boolean isWindows = SystemVersion.isWindows(); - private static final String libPrefix = isWindows ? "" : "lib"; - private static final String libSuffix = isWindows ? ".dll" : ".so"; private static final boolean isLinux = System.getProperty("os.name").toLowerCase(Locale.US).contains("linux"); private static final boolean isKFreebsd = System.getProperty("os.name").toLowerCase(Locale.US).contains("kfreebsd"); private static final boolean isFreebsd = (!isKFreebsd) && System.getProperty("os.name").toLowerCase(Locale.US).contains("freebsd"); @@ -304,13 +301,15 @@ public class CPUID { */ public static CPUInfo getInfo() throws UnknownCPUException { - if(!_nativeOk) - throw new UnknownCPUException("Failed to read CPU information from the system. Please verify the existence of the jcpuid dll/so."); + if(!_nativeOk) { + throw new UnknownCPUException("Failed to read CPU information from the system. Please verify the existence of the " + + getLibraryPrefix() + "jcpuid " + getLibrarySuffix() + " file."); + } String id = getCPUVendorID(); if(id.equals("CentaurHauls")) return new VIAInfoImpl(); if(!isX86) - throw new UnknownCPUException("Failed to read CPU information from the system. The CPUID instruction exists on x86 CPU's only"); + throw new UnknownCPUException("Failed to read CPU information from the system. The CPUID instruction exists on x86 CPUs only."); if(id.equals("AuthenticAMD")) return new AMDInfoImpl(); if(id.equals("GenuineIntel")) @@ -321,9 +320,23 @@ public class CPUID { public static void main(String args[]) { - _doLog = true; - if(!_nativeOk){ - System.out.println("**Failed to retrieve CPUInfo. Please verify the existence of jcpuid dll/so**"); + _doLog = true; // this is too late to log anything from above + String path = System.getProperty("java.library.path"); + String name = getLibraryPrefix() + "jcpuid" + getLibrarySuffix(); + System.out.println("Native library search path: " + path); + if (_nativeOk) { + String sep = System.getProperty("path.separator"); + String[] paths = DataHelper.split(path, sep); + for (String p : paths) { + File f = new File(p, name); + if (f.exists()) { + System.out.println("Found native library: " + f); + break; + } + } + } else { + System.out.println("Failed to retrieve CPUInfo. Please verify the existence of the " + + name + " file in the library path, or set -Djava.library.path=. in the command line"); } System.out.println("JCPUID Version: " + _jcpuidVersion); System.out.println(" **CPUInfo**"); @@ -498,12 +511,22 @@ public class CPUID { * */ private static final boolean loadFromResource() { + // Mac info: + // Through 0.9.25, we had a libjcpuid-x86_64-osx.jnilib and a libjcpuid-x86-osx.jnilib file. + // As of 0.9.26, we have a single libjcpuid-x86_64-osx.jnilib fat binary that has both 64- and 32-bit support. + // For updates, the 0.9.27 update contained the new jbigi.jar. + // However, in rare cases, a user may have skipped that update, going straight + // from 0.9.26 to 0.9.28. Since we can't be sure, always try both for Mac. + // getResourceName64() returns non-null for 64-bit OR for 32-bit Mac. + // try 64 bit first, if getResourceName64() returns non-null String resourceName = getResourceName64(); if (resourceName != null) { boolean success = extractLoadAndCopy(resourceName); if (success) return true; + if (_doLog) + System.err.println("WARNING: Resource name [" + resourceName + "] was not found"); } // now try 32 bit @@ -511,7 +534,6 @@ public class CPUID { boolean success = extractLoadAndCopy(resourceName); if (success) return true; - if (_doLog) System.err.println("WARNING: Resource name [" + resourceName + "] was not found"); return false; @@ -531,7 +553,7 @@ public class CPUID { return false; File outFile = null; FileOutputStream fos = null; - String filename = libPrefix + "jcpuid" + libSuffix; + String filename = getLibraryPrefix() + "jcpuid" + getLibrarySuffix(); try { InputStream libStream = resource.openStream(); outFile = new File(I2PAppContext.getGlobalContext().getTempDir(), filename); @@ -571,17 +593,20 @@ public class CPUID { /** @return non-null */ private static final String getResourceName() { - return getLibraryPrefix()+getLibraryMiddlePart()+"."+getLibrarySuffix(); + return getLibraryPrefix() + getLibraryMiddlePart() + getLibrarySuffix(); } /** - * @return null if not on a 64 bit platform + * @return null if not on a 64 bit platform (except Mac) * @since 0.8.7 */ private static final String getResourceName64() { - if (!is64) + // As of GMP 6, + // libjcpuid-x86_64-osx.jnilib file is a fat binary that contains both 64- and 32-bit binaries + // See loadFromResource() for more info. + if (!is64 && !isMac) return null; - return getLibraryPrefix() + get64LibraryMiddlePart() + "." + getLibrarySuffix(); + return getLibraryPrefix() + get64LibraryMiddlePart() + getLibrarySuffix(); } private static final String getLibraryPrefix() @@ -597,8 +622,14 @@ public class CPUID { return "jcpuid-x86-windows"; // The convention on Windows if(isMac) { if(isX86) { - return "jcpuid-x86-osx"; // The convention on Intel Macs + // As of GMP6, + // our libjcpuid-x86_64.osx.jnilib is a fat binary, + // with the 32-bit lib in it also. + // Not sure if that was on purpose... + return "jcpuid-x86_64-osx"; // The convention on Intel Macs } + // this will fail, we don't have any ppc libs, but we can't return null here. + return "jcpuid-ppc-osx"; } if(isKFreebsd) return "jcpuid-x86-kfreebsd"; // The convention on kfreebsd... @@ -631,6 +662,8 @@ public class CPUID { if(isX86){ return "jcpuid-x86_64-osx"; } + // this will fail, we don't have any ppc libs, but we can't return null here. + return "jcpuid-ppc_64-osx"; } if(isSunos) return "jcpuid-x86_64-solaris"; @@ -641,10 +674,10 @@ public class CPUID { private static final String getLibrarySuffix() { if(isWindows) - return "dll"; + return ".dll"; if(isMac) - return "jnilib"; + return ".jnilib"; else - return "so"; + return ".so"; } } diff --git a/core/java/src/net/i2p/util/NativeBigInteger.java b/core/java/src/net/i2p/util/NativeBigInteger.java index 2b435b2865..6b53b60809 100644 --- a/core/java/src/net/i2p/util/NativeBigInteger.java +++ b/core/java/src/net/i2p/util/NativeBigInteger.java @@ -209,6 +209,9 @@ public class NativeBigInteger extends BigInteger { * Really this could be represented by a DAG, but the benefits don't * outweigh the implementation time. */ + + // none -> {"none"), since 0.9.30 + private final static String[] JBIGI_COMPAT_LIST_NONE = {JBIGI_OPTIMIZATION_X86}; private final static String[] JBIGI_COMPAT_LIST_PPC = {JBIGI_OPTIMIZATION_PPC}; private final static String[] JBIGI_COMPAT_LIST_ARM = {JBIGI_OPTIMIZATION_ARM_CORTEX_A15, JBIGI_OPTIMIZATION_ARM_CORTEX_A9, JBIGI_OPTIMIZATION_ARM_CORTEX_A8, JBIGI_OPTIMIZATION_ARM_CORTEX_A7, JBIGI_OPTIMIZATION_ARM_CORTEX_A5, JBIGI_OPTIMIZATION_ARM_ARMV7, @@ -231,11 +234,14 @@ public class NativeBigInteger extends BigInteger { private final static String[] JBIGI_COMPAT_LIST_INTEL_CORE = {JBIGI_OPTIMIZATION_COREI_BWL, JBIGI_OPTIMIZATION_COREI_HWL, JBIGI_OPTIMIZATION_COREI_SBR, JBIGI_OPTIMIZATION_COREI, JBIGI_OPTIMIZATION_CORE2, JBIGI_OPTIMIZATION_PENTIUMM, JBIGI_OPTIMIZATION_PENTIUM3, JBIGI_OPTIMIZATION_X86}; + /** * The mapping between CPU architecture and its compatibility list. */ @SuppressWarnings("serial") private final static HashMap JBIGI_COMPAT_MAP = new HashMap() {{ + // none -> {"none"), since 0.9.30 + put(JBIGI_OPTIMIZATION_X86, JBIGI_COMPAT_LIST_NONE); put(JBIGI_OPTIMIZATION_PPC, JBIGI_COMPAT_LIST_PPC); put(JBIGI_OPTIMIZATION_ARM_ARMV5, JBIGI_COMPAT_LIST_ARM); @@ -406,10 +412,11 @@ public class NativeBigInteger extends BigInteger { if (intelcpu.IsPentiumCompatible()) return JBIGI_OPTIMIZATION_PENTIUM; } - return null; } catch (UnknownCPUException e) { - return null; } + // always try "none" if we don't know the x86 type, + // in case of CPUID fail or not finding compatibility above + return JBIGI_OPTIMIZATION_X86; } else if (_isArm) { if (_isWin) return null; @@ -739,9 +746,25 @@ public class NativeBigInteger extends BigInteger { */ public static void main(String args[]) { _doLog = true; + String path = System.getProperty("java.library.path"); + String name = _libPrefix + "jbigi" + _libSuffix; + System.out.println("Native library search path: " + path); + if (_nativeOk) { + String sep = System.getProperty("path.separator"); + String[] paths = DataHelper.split(path, sep); + for (String p : paths) { + File f = new File(p, name); + if (f.exists()) { + System.out.println("Found native library: " + f); + break; + } + } + } else { + System.out.println("Failed to load native library. Please verify the existence of the " + + name + " file in the library path, or set -Djava.library.path=. in the command line"); + } boolean nativeOnly = args.length > 0 && args[0].equals("-n"); if (nativeOnly && !_nativeOk) { - System.out.println("Failed to load native library"); System.exit(1); } if (_nativeOk) { @@ -1141,6 +1164,7 @@ public class NativeBigInteger extends BigInteger { return Collections.emptyList(); List rv = new ArrayList(20); String primary = getMiddleName2(true); + // primary may be null String[] compatList = JBIGI_COMPAT_MAP.get(primary); if (primary != null && compatList == null) { @@ -1222,12 +1246,14 @@ public class NativeBigInteger extends BigInteger { /** * @return may be null if optimized is true; returns jbigi-xxx-none if optimize is false */ +/**** private static final String getMiddleName(boolean optimized) { String m2 = getMiddleName2(optimized); if (m2 == null) return null; return getMiddleName1() + m2; } +****/ /** * @return may be null if optimized is true; returns "none" if optimize is false diff --git a/history.txt b/history.txt index 7cbfdac870..de72cc384b 100644 --- a/history.txt +++ b/history.txt @@ -1,3 +1,28 @@ +2017-03-06 zzz + * CPUID: + - Fix saving of libjcpuid.jnifile on Macs, + was incorrectly saving as libjcpuid.so (tickets #1865, #1900) + - Try to load libjcpuid-x86_64-osx.jnilib for 32-bit Macs, + because as of 0.9.26 it's a 'fat binary' with 32-bit in it also. + - Add library search path logging to main() + * NBI: + - Try to load the "none" architecture for x86, even if + CPUID loading fails (tickets #1865, #1900) + - Add library search path logging to main() + * Throttle: Fix disable of probabalistic throttling + (ticket #1963) (thx mysterious) + +2017-03-03 zzz + * Utils: Fix crash in Windows installer + +2017-03-02 zzz + * SSU: + - Initial work on introducer expiration (proposal 133) + - Fix bug in error handling for introduction parameters in RI + +2017-03-01 zzz + * Servlet: Catch OOM in MultiPartRequest + 2017-02-27 zzz * i2psnark: Fix disappearing start button * addressbook: Add date parameter to authentication strings diff --git a/router/java/src/net/i2p/router/RouterVersion.java b/router/java/src/net/i2p/router/RouterVersion.java index 87e5bffca0..282c18b422 100644 --- a/router/java/src/net/i2p/router/RouterVersion.java +++ b/router/java/src/net/i2p/router/RouterVersion.java @@ -18,7 +18,7 @@ public class RouterVersion { /** deprecated */ public final static String ID = "Monotone"; public final static String VERSION = CoreVersion.VERSION; - public final static long BUILD = 1; + public final static long BUILD = 2; /** for example "-test" */ public final static String EXTRA = "";