summaryrefslogtreecommitdiffstats
path: root/src/java/jogamp/common/os/elf/SectionHeader.java
diff options
context:
space:
mode:
authorSven Gothel <[email protected]>2015-02-01 05:21:39 +0100
committerSven Gothel <[email protected]>2015-02-01 05:21:39 +0100
commita3f2d08801c5a54048faca52f422bcededf81b2a (patch)
tree96e83956b62ae3e25043ccc67f4cb1c2c1f232a1 /src/java/jogamp/common/os/elf/SectionHeader.java
parent0deceee37d943faa7c34971388863a27f395d6a5 (diff)
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.
Diffstat (limited to 'src/java/jogamp/common/os/elf/SectionHeader.java')
-rw-r--r--src/java/jogamp/common/os/elf/SectionHeader.java40
1 files changed, 25 insertions, 15 deletions
diff --git a/src/java/jogamp/common/os/elf/SectionHeader.java b/src/java/jogamp/common/os/elf/SectionHeader.java
index 20a40a5..533c04b 100644
--- a/src/java/jogamp/common/os/elf/SectionHeader.java
+++ b/src/java/jogamp/common/os/elf/SectionHeader.java
@@ -133,6 +133,12 @@ public class SectionHeader {
* {@value}
*/
public static final int SHT_ARM_ATTRIBUTES = 0x70000003;
+
+ /**
+ * {@value}. FIXME: Same as {@link #SHT_ARM_ATTRIBUTES}, ok?
+ */
+ public static final int SHT_AARCH64_ATTRIBUTES = 0x70000003;
+
/**
* {@value}
*/
@@ -171,24 +177,28 @@ public class SectionHeader {
*/
public static final short SHN_HIRESERVE = (short)0xffff;
+ /** Public access to the elf header */
+ public final ElfHeaderPart2 eh2;
+
/** Public access to the raw elf section header */
- public final Shdr d;
+ public final Shdr raw;
private final int idx;
private String name;
- SectionHeader(final byte[] buf, final int offset, final int length, final int sectionIdx) {
- this( ByteBuffer.wrap(buf, 0, buf.length), sectionIdx );
+ SectionHeader(final ElfHeaderPart2 eh, final byte[] buf, final int offset, final int length, final int sectionIdx) {
+ this( eh, ByteBuffer.wrap(buf, 0, buf.length), sectionIdx );
}
- SectionHeader(final java.nio.ByteBuffer buf, final int idx) {
- d = Shdr.create(buf);
+ SectionHeader(final ElfHeaderPart2 eh, final java.nio.ByteBuffer buf, final int idx) {
+ this.eh2 = eh;
+ this.raw = Shdr.create(eh.eh1.machDesc.ordinal(), buf);
this.idx = idx;
- name = null;
+ this.name = null;
}
@Override
public String toString() {
- return "SectionHeader[idx "+idx+", name "+name+", type "+toHexString(getType())+", link "+d.getSh_link()+", info "+toHexString(d.getSh_info())+", flags "+toHexString(getFlags())+"]";
+ return "SectionHeader[idx "+idx+", name "+name+", type "+toHexString(getType())+", link "+raw.getSh_link()+", info "+toHexString(raw.getSh_info())+", flags "+toHexString(getFlags())+"]";
}
/**
@@ -206,17 +216,17 @@ public class SectionHeader {
/** Returns the type of this section. */
public int getType() {
- return d.getSh_type();
+ return raw.getSh_type();
}
/** Returns the flags of this section. */
public long getFlags() {
- return d.getSh_flags();
+ return raw.getSh_flags();
}
/** Returns the size of this section. */
public long getSize() {
- return d.getSh_size();
+ return raw.getSh_size();
}
/** Returns this section name, maybe <code>null</code> if not read. */
@@ -232,9 +242,9 @@ public class SectionHeader {
* @throws IllegalArgumentException if section offset or size mismatch including size &gt; {@link Integer#MAX_VALUE}
*/
public Section readSection(final RandomAccessFile in) throws IOException, IllegalArgumentException {
- final int s_size = long2Int(d.getSh_size());
+ final int s_size = long2Int(raw.getSh_size());
if( 0 == s_size || 0 > s_size ) {
- throw new IllegalArgumentException("Shdr["+idx+"] has invalid int size: "+d.getSh_size()+" -> "+s_size);
+ throw new IllegalArgumentException("Shdr["+idx+"] has invalid int size: "+raw.getSh_size()+" -> "+s_size);
}
final byte[] s_buf = new byte[s_size];
return readSectionImpl(in, s_buf, 0, s_size);
@@ -252,9 +262,9 @@ public class SectionHeader {
* @throws IllegalArgumentException if requested read length is &gt; section size
*/
public Section readSection(final RandomAccessFile in, final byte[] b, final int b_off, final int r_len) throws IOException, IllegalArgumentException {
- final int s_size = long2Int(d.getSh_size());
+ final int s_size = long2Int(raw.getSh_size());
if( 0 == s_size || 0 > s_size ) {
- throw new IllegalArgumentException("Shdr["+idx+"] has invalid int size: "+d.getSh_size()+" -> "+s_size);
+ throw new IllegalArgumentException("Shdr["+idx+"] has invalid int size: "+raw.getSh_size()+" -> "+s_size);
}
if( r_len > s_size ) {
throw new IllegalArgumentException("Shdr["+idx+"] has only "+s_size+" bytes, while read request is of "+r_len+" bytes");
@@ -263,7 +273,7 @@ public class SectionHeader {
}
Section readSectionImpl(final RandomAccessFile in, final byte[] b, final int b_off, final int r_len) throws IOException, IllegalArgumentException {
- final long s_off = d.getSh_offset();
+ final long s_off = raw.getSh_offset();
seek(in, s_off);
readBytes(in, b, b_off, r_len);
if( SectionHeader.SHT_ARM_ATTRIBUTES == getType() ) {