forked from java-native-access/jna
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add arm softfloat variant as platform armel
- add prebuild arm softfloat binaries - add option to override prefix detection by specifying jna.prefix - add prefix autodetection to platform code. Autodetection is based on the JVM image - adjust build.xml to implement prefix detection Closes: java-native-access#753
- Loading branch information
1 parent
4f869f4
commit cf56797
Showing
11 changed files
with
517 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
ant-elfanalyser-src/com/sun/jna/BuildArmSoftFloatDetector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
|
||
package com.sun.jna; | ||
|
||
import java.io.File; | ||
import java.io.IOException; | ||
import org.apache.tools.ant.Project; | ||
|
||
/** | ||
* Ant task to expose the arm soft-/hardfloat detection routines of the JNA core | ||
* for the build script. | ||
* | ||
* <p>The build script is expected to build a minimal set of classes that are | ||
* required to execute this. At the time of writing these are:</p> | ||
* | ||
* <ul> | ||
* <li>com.sun.jna.ELFAnalyser</li> | ||
* </ul> | ||
*/ | ||
public class BuildArmSoftFloatDetector { | ||
|
||
private String targetProperty; | ||
private Project project; | ||
|
||
public void setProject(Project proj) { | ||
project = proj; | ||
} | ||
|
||
/** | ||
* targetProperty receives the name of the property, that should take the | ||
* new property | ||
* | ||
* @param targetProperty | ||
*/ | ||
public void setTargetProperty(String targetProperty) { | ||
this.targetProperty = targetProperty; | ||
} | ||
|
||
public void execute() throws IOException { | ||
boolean result = false; | ||
// On linux /proc/self/exe is a symblink to the currently executing | ||
// binary (the JVM) | ||
File self = new File("/proc/self/exe"); | ||
try { | ||
// The self.getCanonicalPath() resolves the symblink to the backing | ||
// realfile and passes that to the detection routines | ||
ELFAnalyser ahfd = ELFAnalyser.analyse(self.getCanonicalPath()); | ||
result = ahfd.isArmSoftFloat(); | ||
} catch (IOException ex) { | ||
result = false; | ||
} | ||
project.setNewProperty(targetProperty, Boolean.toString(result)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://www.netbeans.org/ns/project/1"> | ||
<type>org.netbeans.modules.ant.freeform</type> | ||
<configuration> | ||
<general-data xmlns="http://www.netbeans.org/ns/freeform-project/1"> | ||
<name>JNA</name> | ||
</general-data> | ||
<general-data xmlns="http://www.netbeans.org/ns/freeform-project/2"> | ||
<!-- Do not use Project Properties customizer when editing this file manually. | ||
To prevent the customizer from showing, create nbproject/project.properties file and enter | ||
auxiliary.show.customizer=false | ||
property there. Adding | ||
auxiliary.show.customizer.message=<message> | ||
will show your customized message when someone attempts to open the customizer. --> | ||
<name>JNA</name> | ||
<properties/> | ||
<folders> | ||
<source-folder> | ||
<label>JNA</label> | ||
<location>.</location> | ||
<encoding>UTF-8</encoding> | ||
</source-folder> | ||
<source-folder> | ||
<label>src</label> | ||
<type>java</type> | ||
<location>src</location> | ||
<encoding>UTF-8</encoding> | ||
</source-folder> | ||
<source-folder> | ||
<label>test</label> | ||
<type>java</type> | ||
<location>test</location> | ||
<encoding>UTF-8</encoding> | ||
</source-folder> | ||
<source-folder> | ||
<label>ant-elfanalyser-src</label> | ||
<type>java</type> | ||
<location>ant-elfanalyser-src</location> | ||
<encoding>UTF-8</encoding> | ||
</source-folder> | ||
</folders> | ||
<ide-actions> | ||
<action name="build"> | ||
<target>jar</target> | ||
</action> | ||
<action name="clean"> | ||
<target>clean</target> | ||
</action> | ||
<action name="javadoc"> | ||
<target>javadoc</target> | ||
</action> | ||
<action name="test"> | ||
<target>test</target> | ||
</action> | ||
<action name="rebuild"> | ||
<target>clean</target> | ||
<target>jar</target> | ||
</action> | ||
</ide-actions> | ||
<view> | ||
<items> | ||
<source-folder style="packages"> | ||
<label>src</label> | ||
<location>src</location> | ||
</source-folder> | ||
<source-folder style="packages"> | ||
<label>test</label> | ||
<location>test</location> | ||
</source-folder> | ||
<source-folder style="packages"> | ||
<label>ant-elfanalyser-src</label> | ||
<location>ant-elfanalyser-src</location> | ||
</source-folder> | ||
<source-file> | ||
<location>build.xml</location> | ||
</source-file> | ||
</items> | ||
<context-menu> | ||
<ide-action name="build"/> | ||
<ide-action name="rebuild"/> | ||
<ide-action name="clean"/> | ||
<ide-action name="javadoc"/> | ||
<ide-action name="test"/> | ||
</context-menu> | ||
</view> | ||
<subprojects/> | ||
</general-data> | ||
<java-data xmlns="http://www.netbeans.org/ns/freeform-project-java/2"> | ||
<compilation-unit> | ||
<package-root>src</package-root> | ||
<classpath mode="compile">src</classpath> | ||
<source-level>1.5</source-level> | ||
</compilation-unit> | ||
<compilation-unit> | ||
<package-root>test</package-root> | ||
<unit-tests/> | ||
<classpath mode="compile">lib/hamcrest-core-1.3.jar:lib/junit.jar:lib/test/dom4j-1.6.1.jar:lib/test/guava-11.0.2.jar:lib/test/javassist-3.12.1.GA.jar:lib/test/reflections-0.9.8.jar:lib/test/slf4j-api-1.6.1.jar:src</classpath> | ||
<source-level>1.5</source-level> | ||
</compilation-unit> | ||
<compilation-unit> | ||
<package-root>ant-elfanalyser-src</package-root> | ||
<classpath mode="compile">src:lib/ant.jar</classpath> | ||
<source-level>1.5</source-level> | ||
</compilation-unit> | ||
</java-data> | ||
</configuration> | ||
</project> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
|
||
package com.sun.jna; | ||
|
||
import java.io.IOException; | ||
import java.io.RandomAccessFile; | ||
import java.nio.ByteBuffer; | ||
import java.nio.ByteOrder; | ||
import java.util.Arrays; | ||
|
||
/** | ||
* Analyse an ELF file for platform specific attributes. | ||
* | ||
* <p>Primary use-case: Detect whether the java binary is arm hardfloat or softfloat.</p> | ||
*/ | ||
class ELFAnalyser { | ||
/** | ||
* Generic ELF header | ||
*/ | ||
private static final byte[] ELF_MAGIC = new byte[]{(byte) 0x7F, (byte) 'E', (byte) 'L', (byte) 'F'}; | ||
/** | ||
* e_flags mask if executable file conforms to hardware floating-point | ||
* procedure-call standard (arm ABI version 5) | ||
*/ | ||
private static final int EF_ARM_ABI_FLOAT_HARD = 0x00000400; | ||
/** | ||
* e_flags mask if executable file conforms to software floating-point | ||
* procedure-call standard (arm ABI version 5) | ||
*/ | ||
private static final int EF_ARM_ABI_FLOAT_SOFT = 0x00000200; | ||
private static final int EI_DATA_BIG_ENDIAN = 2; | ||
private static final int E_MACHINE_ARM = 0x28; | ||
private static final int EI_CLASS_64BIT = 2; | ||
|
||
public static ELFAnalyser analyse(String filename) throws IOException { | ||
ELFAnalyser res = new ELFAnalyser(filename); | ||
res.runDetection(); | ||
return res; | ||
} | ||
|
||
private final String filename; | ||
private boolean ELF = false; | ||
private boolean _64Bit = false; | ||
private boolean bigEndian = false; | ||
private boolean armHardFloat = false; | ||
private boolean armSoftFloat = false; | ||
private boolean arm = false; | ||
|
||
/** | ||
* @return true if the parsed file was detected to be an ELF file | ||
*/ | ||
public boolean isELF() { | ||
return ELF; | ||
} | ||
|
||
/** | ||
* @return true if the parsed file was detected to be for a 64bit architecture | ||
* and pointers are expected to be 8byte wide | ||
*/ | ||
public boolean is64Bit() { | ||
return _64Bit; | ||
} | ||
|
||
/** | ||
* @return true if the parsed file is detected to be big endian, false if | ||
* the file is little endian | ||
*/ | ||
public boolean isBigEndian() { | ||
return bigEndian; | ||
} | ||
|
||
/** | ||
* @return filename of the parsed file | ||
*/ | ||
public String getFilename() { | ||
return filename; | ||
} | ||
|
||
/** | ||
* @return true if file was detected to conform to the hardware floating-point | ||
* procedure-call standard | ||
*/ | ||
public boolean isArmHardFloat() { | ||
return armHardFloat; | ||
} | ||
|
||
/** | ||
* @return true if file was detected to conform to the software floating-point | ||
* procedure-call standard | ||
*/ | ||
public boolean isArmSoftFloat() { | ||
return armSoftFloat; | ||
} | ||
|
||
/** | ||
* @return true if the parsed file was detected to be build for the arm | ||
* architecture | ||
*/ | ||
public boolean isArm() { | ||
return arm; | ||
} | ||
|
||
private ELFAnalyser(String filename) { | ||
this.filename = filename; | ||
} | ||
|
||
private void runDetection() throws IOException { | ||
// run precheck - only of if the file at least hold an ELF header parsing | ||
// runs further. | ||
RandomAccessFile raf = new RandomAccessFile(filename, "r"); | ||
if (raf.length() > 4) { | ||
byte[] magic = new byte[4]; | ||
raf.seek(0); | ||
raf.read(magic); | ||
if (Arrays.equals(magic, ELF_MAGIC)) { | ||
ELF = true; | ||
} | ||
} | ||
if (!ELF) { | ||
return; | ||
} | ||
raf.seek(4); | ||
// The total header size depends on the pointer size of the platform | ||
// so before the header is loaded the pointer size has to be determined | ||
byte sizeIndicator = raf.readByte(); | ||
_64Bit = sizeIndicator == EI_CLASS_64BIT; | ||
raf.seek(0); | ||
ByteBuffer headerData = ByteBuffer.allocate(_64Bit ? 64 : 52); | ||
raf.getChannel().read(headerData, 0); | ||
bigEndian = headerData.get(5) == EI_DATA_BIG_ENDIAN; | ||
headerData.order(bigEndian ? ByteOrder.BIG_ENDIAN : ByteOrder.LITTLE_ENDIAN); | ||
|
||
arm = headerData.get(0x12) == E_MACHINE_ARM; | ||
|
||
if(arm) { | ||
int flags = headerData.getInt(_64Bit ? 0x30 : 0x24); | ||
armSoftFloat = (flags & EF_ARM_ABI_FLOAT_SOFT) == EF_ARM_ABI_FLOAT_SOFT; | ||
armHardFloat = (flags & EF_ARM_ABI_FLOAT_HARD) == EF_ARM_ABI_FLOAT_HARD; | ||
} | ||
} | ||
} |
Oops, something went wrong.