Skip to content

Ghidra is a software reverse engineering (SRE) framework

Merge remote-tracking branch 'origin/Ghidra_12.1'

Ryan Kurtz64c5b4e9af68
diff --cc Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/processors/sleigh/SleighLanguage.java
index 5c05cd94bc,812a851428..a696a6394a
--- a/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/processors/sleigh/SleighLanguage.java
+++ b/Ghidra/Framework/SoftwareModeling/src/main/java/ghidra/app/plugin/processors/sleigh/SleighLanguage.java
@@@ -70,7 -70,8 +70,8 @@@ public class SleighLanguage implements
private int numSections = 0; // Number of named sections for this language
private int alignment = 1;
private int defaultPointerWordSize = 1; // Default wordsize to send down with pointer data-types
+ private OptionalInt maxInstructionLength = OptionalInt.empty();
- private SleighLanguageDescription description;
+ private final SleighLanguageDescription description;
private ParallelInstructionLanguageHelper parallelHelper;
private SourceFileIndexer indexer; //used to provide source file info for constructors
@@@ -130,56 -125,27 +131,57 @@@
(SleighCompilerSpecDescription) compilerSpecDescription);
}
compilerSpecs = new HashMap<>();
- this.description = langDescription;
additionalInject = null;
- SleighLanguageValidator.validatePspecFile(langDescription.getSpecFile());
+ SleighLanguageValidator.validatePspecFile(description.getSpecFile());
- readInitialDescription();
- // should addressFactory and registers initialization be done at construction time?
- // for now we'll assume yes.
+ readInitialDescription(); // process pspec file
+
- // should addressFactory and registers initialization be done at
- // construction time?
- // for now we'll assume yes.
++ // Should addressFactory and registers initialization be done at construction time?
++ // For now we'll assume yes.
contextcache = new ContextCache();
-
- ResourceFile slaFile = langDescription.getSlaFile();
- if (!slaFile.exists() ||
- (slaFile.canWrite() && (isSLAWrongVersion(slaFile) || isSLAStale(slaFile)))) {
- reloadLanguage(TaskMonitor.DUMMY, true);
+
+ SleighLanguageFile langFile = description.getLanguageFile();
+ if (!langFile.getSlaSpecFile().exists()) {
+ throw new SleighFileException("Missing slaspec: " + langFile.getSlaSpecFile());
+ }
+
+ // check .sla file freshness inside lock, and recompile if necessary before releasing lock.
+ // if can't lock, it's single jar mode and we can't recompile anyways
+ AtomicLong lockElapsed = new AtomicLong();
+ if (langFile.canLock()) {
+ try (PreserveStateWrappingTaskMonitor tm =
+ new PreserveStateWrappingTaskMonitor(monitor)) {
+ tm.setCancelEnabled(true);
+ tm.setShowProgressValue(true);
+ langFile.withLock(SleighLanguageProvider.LANGUAGE_LOCK_TIMEOUT, tm, () -> {
+ tm.setCancelEnabled(false);
+ long lockStartTS = System.currentTimeMillis();
+ if (forceCompile || langFile.needsCompilation(SlaFormat.FORMAT_VERSION)) {
+ langFile.compileSlaFile(monitor);
+ }
+ lockElapsed.set(System.currentTimeMillis() - lockStartTS);
+ });
+ }
+ catch (TimeoutException e) {
+ throw new SleighFileLockException(
+ "Timeout waiting for Sleigh language file lock: %s"
+ .formatted(langFile.getSlaFile()),
+ e);
+ }
+ catch (IOException e) {
+ throw new SleighFileException(
+ "Error locking Sleigh language file %s".formatted(langFile.getSlaFile()), e);
+ }
}
-
+
// Read in the sleigh specification
- PackedDecode decoder = SlaFormat.buildDecoder(slaFile);
- decode(decoder);
+ try (PackedDecode decoder = SlaFormat.buildDecoder(langFile.getSlaFile())) {
+ decode(decoder);
+ }
+ catch (IOException | DecoderException e) {
+ throw new SleighException("Error decoding", e);
+ }
registerBuilder = new RegisterBuilder();
loadRegisters(registerBuilder);
@@@ -191,9 -157,12 +193,15 @@@
initParallelHelper();
+ int maxLength =
+ getPropertyAsInt(GhidraLanguagePropertyKeys.MAXIMUM_INSTRUCTION_LENGTH, -1);
+ if (maxLength > 0) {
+ maxInstructionLength = OptionalInt.of(maxLength);
+ }
+
+ long initElapsed = System.currentTimeMillis() - startTS;
+ Msg.debug(this, "Took %dms (%dms inside lock) to initialize language %s"
+ .formatted(initElapsed, lockElapsed.get(), langFile));
}
private void buildVolatileSymbolAddresses() {