package jogamp.common.os;
import java.io.File;
import java.io.IOException;
import java.io.RandomAccessFile;
import java.nio.ByteBuffer;
import java.nio.IntBuffer;
import java.nio.ShortBuffer;
import java.security.AccessController;
import java.security.PrivilegedAction;
import java.util.List;
import jogamp.common.Debug;
import jogamp.common.os.elf.ElfHeaderPart1;
import jogamp.common.os.elf.ElfHeaderPart2;
import jogamp.common.os.elf.SectionArmAttributes;
import com.jogamp.common.nio.Buffers;
import com.jogamp.common.os.AndroidVersion;
import com.jogamp.common.os.NativeLibrary;
import com.jogamp.common.os.Platform;
import com.jogamp.common.os.Platform.ABIType;
import com.jogamp.common.os.Platform.CPUFamily;
import com.jogamp.common.os.Platform.CPUType;
import com.jogamp.common.os.Platform.OSType;
import com.jogamp.common.util.VersionNumber;
/**
* Abstract parent class of {@link Platform} initializing and holding
* platform information, which are initialized independent
* of other classes.
*
* This class is not intended to be exposed in the public namespace
* and solely exist to solve initialization interdependencies.
* Please use {@link Platform} to access the public fields!
*
*/
public abstract class PlatformPropsImpl {
static final boolean DEBUG = Debug.debug("Platform");
/** Selected {@link Platform.OSType#MACOS} {@link VersionNumber}s. */
public static class OSXVersion {
/** OSX Tiger, i.e. 10.4.0 */
public static final VersionNumber Tiger = new VersionNumber(10,4,0);
/** OSX Lion, i.e. 10.7.0 */
public static final VersionNumber Lion = new VersionNumber(10,7,0);
/** OSX Mavericks, i.e. 10.9.0 */
public static final VersionNumber Mavericks = new VersionNumber(10,9,0);
}
/**
* Returns {@code true} if the given {@link CPUType}s and {@link ABIType}s are compatible.
*/
public static final boolean isCompatible(final CPUType cpu1, final ABIType abi1, final CPUType cpu2, final ABIType abi2) {
return cpu1.isCompatible(cpu2) && abi1.isCompatible(abi2);
}
//
// static initialization order:
//
/** Version 1.6. As a JVM version, it enables certain JVM 1.6 features. */
public static final VersionNumber Version16;
/** Version 1.7. As a JVM version, it enables certain JVM 1.7 features. */
public static final VersionNumber Version17;
public static final String OS;
public static final String OS_lower;
public static final String OS_VERSION;
public static final VersionNumber OS_VERSION_NUMBER;
public static final String ARCH;
public static final String ARCH_lower;
public static final String JAVA_VENDOR;
public static final String JAVA_VENDOR_URL;
public static final String JAVA_VERSION;
public static final VersionNumber JAVA_VERSION_NUMBER;
public static final int JAVA_VERSION_UPDATE;
public static final String JAVA_VM_NAME;
public static final String JAVA_RUNTIME_NAME;
/** True if having {@link java.nio.LongBuffer} and {@link java.nio.DoubleBuffer} available. */
public static final boolean JAVA_SE;
/**
* True only if being compatible w/ language level 6, e.g. JRE 1.6.
*
* Implies {@link #isJavaSE()}.
*
*
* Note: We claim Android is compatible.
*
*/
public static final boolean JAVA_6;
public static final String NEWLINE;
public static final boolean LITTLE_ENDIAN;
public static final CPUType CPU_ARCH;
public static final ABIType ABI_TYPE;
public static final OSType OS_TYPE;
public static final String os_and_arch;
static {
Version16 = new VersionNumber(1, 6, 0);
Version17 = new VersionNumber(1, 7, 0);
// We don't seem to need an AccessController.doPrivileged() block
// here as these system properties are visible even to unsigned Applets.
final boolean isAndroid = AndroidVersion.isAvailable; // also triggers it's static initialization
JAVA_VENDOR = System.getProperty("java.vendor");
JAVA_VENDOR_URL = System.getProperty("java.vendor.url");
JAVA_VERSION = System.getProperty("java.version");
JAVA_VERSION_NUMBER = new VersionNumber(JAVA_VERSION);
{
int usIdx = JAVA_VERSION.lastIndexOf("-u"); // OpenJDK update notation
int usOff;
if( 0 < usIdx ) {
usOff = 2;
} else {
usIdx = JAVA_VERSION.lastIndexOf("_"); // Oracle update notation
usOff = 1;
}
if( 0 < usIdx ) {
final String buildS = PlatformPropsImpl.JAVA_VERSION.substring(usIdx+usOff);
final VersionNumber update = new VersionNumber(buildS);
JAVA_VERSION_UPDATE = update.getMajor();
} else {
JAVA_VERSION_UPDATE = 0;
}
}
JAVA_VM_NAME = System.getProperty("java.vm.name");
JAVA_RUNTIME_NAME = getJavaRuntimeNameImpl();
JAVA_SE = initIsJavaSE();
JAVA_6 = JAVA_SE && ( isAndroid || JAVA_VERSION_NUMBER.compareTo(Version16) >= 0 ) ;
NEWLINE = System.getProperty("line.separator");
OS = System.getProperty("os.name");
OS_lower = OS.toLowerCase();
OS_VERSION = System.getProperty("os.version");
OS_VERSION_NUMBER = new VersionNumber(OS_VERSION);
OS_TYPE = getOSTypeImpl(OS_lower, isAndroid);
// Hard values, i.e. w/ probing binaries
final String elfCpuName;
final CPUType elfCpuType;
final ABIType elfABIType;
final int elfLittleEndian;
final boolean elfValid;
{
final String[] _elfCpuName = { null };
final CPUType[] _elfCpuType = { null };
final ABIType[] _elfAbiType = { null };
final int[] _elfLittleEndian = { 0 }; // 1 - little, 2 - big
final boolean[] _elfValid = { false };
AccessController.doPrivileged(new PrivilegedAction