mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 10:19:23 +02:00
GP-4712 refactoring, adding back in cache with no locking
This commit is contained in:
parent
7e5ffc2cf3
commit
19cf2fba3c
3 changed files with 21 additions and 11 deletions
|
@ -15,16 +15,19 @@
|
||||||
*/
|
*/
|
||||||
package ghidra.app.plugin.processors.sleigh;
|
package ghidra.app.plugin.processors.sleigh;
|
||||||
|
|
||||||
import ghidra.program.model.address.Address;
|
|
||||||
import ghidra.program.model.lang.*;
|
|
||||||
|
|
||||||
import java.math.BigInteger;
|
import java.math.BigInteger;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
|
import generic.stl.Pair;
|
||||||
|
import ghidra.program.model.address.Address;
|
||||||
|
import ghidra.program.model.lang.*;
|
||||||
|
|
||||||
public class ContextCache {
|
public class ContextCache {
|
||||||
private int context_size = 0;
|
private int context_size = 0;
|
||||||
private Register contextBaseRegister = null;
|
private Register contextBaseRegister = null;
|
||||||
|
|
||||||
|
Pair <BigInteger, int []> lastValue = null;
|
||||||
|
|
||||||
public ContextCache() {
|
public ContextCache() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,7 +58,13 @@ public class ContextCache {
|
||||||
|
|
||||||
private int[] getWords(BigInteger value) {
|
private int[] getWords(BigInteger value) {
|
||||||
|
|
||||||
|
Pair <BigInteger, int []> lastValueTmp = lastValue;
|
||||||
|
if (lastValueTmp != null && value.equals(lastValueTmp.first)) {
|
||||||
|
return lastValueTmp.second;
|
||||||
|
}
|
||||||
|
|
||||||
int[] words = new int[context_size];
|
int[] words = new int[context_size];
|
||||||
|
|
||||||
byte[] bytes = value.toByteArray();
|
byte[] bytes = value.toByteArray();
|
||||||
int byteIndexDiff = context_size * 4 - bytes.length;
|
int byteIndexDiff = context_size * 4 - bytes.length;
|
||||||
for (int i = 0; i < context_size; i++) {
|
for (int i = 0; i < context_size; i++) {
|
||||||
|
@ -66,6 +75,10 @@ public class ContextCache {
|
||||||
}
|
}
|
||||||
words[i] = word;
|
words[i] = word;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lastValueTmp = new Pair<BigInteger, int[]>(value, words);
|
||||||
|
lastValue = lastValueTmp;
|
||||||
|
|
||||||
return words;
|
return words;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -378,13 +378,12 @@ public class SleighLanguage implements Language {
|
||||||
if (!instructProtoMap.containsKey(hashcode)) {
|
if (!instructProtoMap.containsKey(hashcode)) {
|
||||||
newProto.cacheInfo(buf, context, true);
|
newProto.cacheInfo(buf, context, true);
|
||||||
}
|
}
|
||||||
|
res = instructProtoMap.putIfAbsent(hashcode, newProto);
|
||||||
res = instructProtoMap.get(hashcode);
|
// if there was no previous value, assume newProto inserted
|
||||||
if (res == null) { // We have a prototype we have never seen
|
if (res == null) {
|
||||||
// before, build it fully
|
|
||||||
instructProtoMap.put(hashcode, newProto);
|
|
||||||
res = newProto;
|
res = newProto;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (inDelaySlot && res.hasDelaySlots()) {
|
if (inDelaySlot && res.hasDelaySlots()) {
|
||||||
throw new NestedDelaySlotException();
|
throw new NestedDelaySlotException();
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,6 @@ public class HighFunction extends PcodeSyntaxTree {
|
||||||
private List<JumpTable> jumpTables;
|
private List<JumpTable> jumpTables;
|
||||||
private List<DataTypeSymbol> protoOverrides;
|
private List<DataTypeSymbol> protoOverrides;
|
||||||
private Address entryPoint;
|
private Address entryPoint;
|
||||||
private AddressSpace entryAddrSpace;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param function function associated with the higher level function abstraction.
|
* @param function function associated with the higher level function abstraction.
|
||||||
|
@ -67,7 +66,6 @@ public class HighFunction extends PcodeSyntaxTree {
|
||||||
this.compilerSpec = compilerSpec;
|
this.compilerSpec = compilerSpec;
|
||||||
AddressSpace stackSpace = function.getProgram().getAddressFactory().getStackSpace();
|
AddressSpace stackSpace = function.getProgram().getAddressFactory().getStackSpace();
|
||||||
entryPoint = function.getEntryPoint();
|
entryPoint = function.getEntryPoint();
|
||||||
entryAddrSpace = entryPoint.getAddressSpace();
|
|
||||||
localSymbols = new LocalSymbolMap(this, stackSpace);
|
localSymbols = new LocalSymbolMap(this, stackSpace);
|
||||||
globalSymbols = new GlobalSymbolMap(this);
|
globalSymbols = new GlobalSymbolMap(this);
|
||||||
proto = new FunctionPrototype(localSymbols, function);
|
proto = new FunctionPrototype(localSymbols, function);
|
||||||
|
@ -304,7 +302,7 @@ public class HighFunction extends PcodeSyntaxTree {
|
||||||
private void decodeJumpTableList(Decoder decoder) throws DecoderException {
|
private void decodeJumpTableList(Decoder decoder) throws DecoderException {
|
||||||
int el = decoder.openElement(ELEM_JUMPTABLELIST);
|
int el = decoder.openElement(ELEM_JUMPTABLELIST);
|
||||||
while (decoder.peekElement() != 0) {
|
while (decoder.peekElement() != 0) {
|
||||||
JumpTable table = new JumpTable(entryAddrSpace);
|
JumpTable table = new JumpTable(entryPoint.getAddressSpace());
|
||||||
table.decode(decoder);
|
table.decode(decoder);
|
||||||
if (!table.isEmpty()) {
|
if (!table.isEmpty()) {
|
||||||
if (jumpTables == null) {
|
if (jumpTables == null) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue