From a3f2d08801c5a54048faca52f422bcededf81b2a Mon Sep 17 00:00:00 2001
From: Sven Gothel
Date: Sun, 1 Feb 2015 05:21:39 +0100
Subject: Bug 1125 - Make ELF Reader 'jogamp.common.os.elf' Stateless
ELF Reader 'jogamp.common.os.elf' currently uses
Platform's pre-determined OS_TYPE and CPUType.
It also uses the host platforms MachineDescription,
hence can not read ELF files from other machines.
This also forbids Platform to determine CPUType etc
w/o having a valid 'os.arch' property.
+++
ElfHeader should be split in
- ElfHeaderPart1 (CPUType independent)
- ElfHeaderPart2 (CPUType dependent)
Fix shall make the ELF Reader self containing
by only using ELF CPUType data, etc.
This requires customization of struct parsing,
where MachineDescription.Static index shall be
- defined in ElfHeaderPart1 using e_Ident's CPUType.
- used in ElfHeaderPart2 and all its struct types.
---
src/java/jogamp/common/os/PlatformPropsImpl.java | 405 ++++++++++++-----------
1 file changed, 205 insertions(+), 200 deletions(-)
(limited to 'src/java/jogamp/common/os/PlatformPropsImpl.java')
diff --git a/src/java/jogamp/common/os/PlatformPropsImpl.java b/src/java/jogamp/common/os/PlatformPropsImpl.java
index b12ab6f..b35533f 100644
--- a/src/java/jogamp/common/os/PlatformPropsImpl.java
+++ b/src/java/jogamp/common/os/PlatformPropsImpl.java
@@ -11,9 +11,9 @@ import java.security.PrivilegedAction;
import java.util.List;
import jogamp.common.Debug;
-import jogamp.common.os.elf.ElfHeader;
+import jogamp.common.os.elf.ElfHeaderPart1;
+import jogamp.common.os.elf.ElfHeaderPart2;
import jogamp.common.os.elf.SectionArmAttributes;
-import jogamp.common.os.elf.SectionHeader;
import com.jogamp.common.nio.Buffers;
import com.jogamp.common.os.AndroidVersion;
@@ -48,6 +48,13 @@ public abstract class PlatformPropsImpl {
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:
//
@@ -72,14 +79,20 @@ public abstract class PlatformPropsImpl {
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 if being compatible w/ language level 6, e.g. JRE 1.6. Implies {@link #JAVA_SE}. Note: We claim Android is compatible. */
+ /**
+ * 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;
- /* pp */ static final CPUType sCpuType;
-
public static final CPUType CPU_ARCH;
public static final ABIType ABI_TYPE;
public static final OSType OS_TYPE;
@@ -126,111 +139,191 @@ public abstract class PlatformPropsImpl {
OS_VERSION_NUMBER = new VersionNumber(OS_VERSION);
OS_TYPE = getOSTypeImpl(OS_lower, isAndroid);
- LITTLE_ENDIAN = queryIsLittleEndianImpl();
-
- // Soft values, i.e. w/o probing binaries
- final String sARCH = System.getProperty("os.arch");
- final String sARCH_lower = sARCH.toLowerCase();
- sCpuType = getCPUTypeImpl(sARCH_lower);
- if( DEBUG ) {
- System.err.println("Platform.Soft: sARCH "+sARCH+", sCpuType "+sCpuType);
- if( isAndroid ) {
- System.err.println("Android: CPU_ABI1 str "+AndroidVersion.CPU_ABI+", CPU_TYPE "+AndroidVersion.CPU_TYPE+", ABI_TYPE "+AndroidVersion.ABI_TYPE);
- System.err.println("Android: CPU_ABI2 str "+AndroidVersion.CPU_ABI2+", CPU_TYPE2 "+AndroidVersion.CPU_TYPE2+", ABI_TYPE2 "+AndroidVersion.ABI_TYPE2);
- }
- }
-
// Hard values, i.e. w/ probing binaries
//
// FIXME / HACK:
- // We use sCPUType for MachineDescriptionRuntime.getStatic()
+ // We use preCpuType for MachineDescriptionRuntime.getStatic()
// until we have determined the final CPU_TYPE, etc.
// MachineDescriptionRuntime gets notified via MachineDescriptionRuntime.notifyPropsInitialized() below.
//
// We could use Elf Ehdr's machine value to determine the bit-size
// used for it's offset table!
// However, 'os.arch' should be a good guess for this task.
+ final String elfCpuName;
final CPUType elfCpuType;
- final ABIType elfAbiType;
+ final ABIType elfABIType;
+ final int elfLittleEndian;
final boolean elfValid;
{
- final CPUType[] _ehCpuType = { null };
- final ABIType[] _ehAbiType = { null };
- final ElfHeader eh = queryABITypeImpl(OS_TYPE, _ehCpuType, _ehAbiType);
- if( null != eh && null != _ehCpuType[0] && null != _ehAbiType[0] ) {
- elfCpuType = _ehCpuType[0];
- elfAbiType = _ehAbiType[0];
- if( isAndroid ) {
- final CPUFamily aCpuFamily1 = null != AndroidVersion.CPU_TYPE ? AndroidVersion.CPU_TYPE.family : null;
- final CPUFamily aCpuFamily2 = null != AndroidVersion.CPU_TYPE2 ? AndroidVersion.CPU_TYPE2.family : null;
- if( elfCpuType.family != aCpuFamily1 && elfCpuType.family != aCpuFamily2 ) {
- // Ooops !
- elfValid = false;
- } else {
- elfValid = true;
- }
- } else {
- if( elfCpuType.family != sCpuType.family ) {
- // Ooops !
- elfValid = false;
- } else {
- elfValid = true;
+ 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