mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-05 02:39:44 +02:00
GP-1161: Including uniques in thread-local state, and renaming things by those terms.
This commit is contained in:
parent
0c56f638a3
commit
237b7c00d1
8 changed files with 53 additions and 49 deletions
|
@ -70,13 +70,13 @@ public class DebuggerTracePcodeEmulator extends TracePcodeEmulator {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected PcodeExecutorState<byte[]> createMemoryState() {
|
||||
protected PcodeExecutorState<byte[]> createSharedState() {
|
||||
return new ReadsTargetMemoryPcodeExecutorState(tool, trace, snap, null, 0,
|
||||
recorder);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PcodeExecutorState<byte[]> createRegisterState(PcodeThread<byte[]> emuThread) {
|
||||
protected PcodeExecutorState<byte[]> createLocalState(PcodeThread<byte[]> emuThread) {
|
||||
TraceThread traceThread =
|
||||
trace.getThreadManager().getLiveThreadByPath(snap, emuThread.getName());
|
||||
return new ReadsTargetRegistersPcodeExecutorState(tool, trace, snap, traceThread, 0,
|
||||
|
|
|
@ -55,12 +55,12 @@ public class TracePcodeEmulator extends AbstractPcodeEmulator {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected PcodeExecutorState<byte[]> createMemoryState() {
|
||||
protected PcodeExecutorState<byte[]> createSharedState() {
|
||||
return newState(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PcodeExecutorState<byte[]> createRegisterState(PcodeThread<byte[]> emuThread) {
|
||||
protected PcodeExecutorState<byte[]> createLocalState(PcodeThread<byte[]> emuThread) {
|
||||
return newState(trace.getThreadManager().getLiveThreadByPath(snap, emuThread.getName()));
|
||||
}
|
||||
|
||||
|
@ -79,13 +79,13 @@ public class TracePcodeEmulator extends AbstractPcodeEmulator {
|
|||
* @param synthesizeStacks true to synthesize the innermost stack frame of each thread
|
||||
*/
|
||||
public void writeDown(Trace trace, long destSnap, long threadsSnap, boolean synthesizeStacks) {
|
||||
TraceCachedWriteBytesPcodeExecutorState ms =
|
||||
(TraceCachedWriteBytesPcodeExecutorState) getMemoryState();
|
||||
ms.writeCacheDown(trace, destSnap, null, 0);
|
||||
TraceCachedWriteBytesPcodeExecutorState ss =
|
||||
(TraceCachedWriteBytesPcodeExecutorState) getSharedState();
|
||||
ss.writeCacheDown(trace, destSnap, null, 0);
|
||||
TraceThreadManager threadManager = trace.getThreadManager();
|
||||
for (PcodeThread<byte[]> emuThread : threads.values()) {
|
||||
TraceCachedWriteBytesPcodeExecutorState rs =
|
||||
(TraceCachedWriteBytesPcodeExecutorState) emuThread.getState().getRegisterState();
|
||||
TraceCachedWriteBytesPcodeExecutorState ls =
|
||||
(TraceCachedWriteBytesPcodeExecutorState) emuThread.getState().getLocalState();
|
||||
TraceThread traceThread = threadManager.getLiveThreadByPath(
|
||||
threadsSnap, emuThread.getName());
|
||||
if (traceThread == null) {
|
||||
|
@ -93,7 +93,7 @@ public class TracePcodeEmulator extends AbstractPcodeEmulator {
|
|||
"Given trace does not have thread with name/path '" + emuThread.getName() +
|
||||
"' at snap " + destSnap);
|
||||
}
|
||||
rs.writeCacheDown(trace, destSnap, traceThread, 0);
|
||||
ls.writeCacheDown(trace, destSnap, traceThread, 0);
|
||||
if (synthesizeStacks) {
|
||||
TraceStack stack = trace.getStackManager().getStack(traceThread, destSnap, true);
|
||||
stack.getFrame(0, true).setProgramCounter(emuThread.getCounter());
|
||||
|
|
|
@ -385,12 +385,12 @@ public class TraceScheduleTest extends AbstractGhidraHeadlessIntegrationTest {
|
|||
}
|
||||
|
||||
@Override
|
||||
protected PcodeExecutorState<Void> createMemoryState() {
|
||||
protected PcodeExecutorState<Void> createSharedState() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected PcodeExecutorState<Void> createRegisterState(PcodeThread<Void> thread) {
|
||||
protected PcodeExecutorState<Void> createLocalState(PcodeThread<Void> thread) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ public abstract class AbstractPcodeMachine<T> implements PcodeMachine<T> {
|
|||
protected final SleighUseropLibrary<T> stubLibrary;
|
||||
|
||||
/* for abstract thread access */ PcodeStateInitializer initializer;
|
||||
private PcodeExecutorState<T> memoryState;
|
||||
private PcodeExecutorState<T> sharedState;
|
||||
protected final Map<String, PcodeThread<T>> threads = new LinkedHashMap<>();
|
||||
|
||||
protected final Map<Address, PcodeProgram> injects = new HashMap<>();
|
||||
|
@ -55,9 +55,9 @@ public abstract class AbstractPcodeMachine<T> implements PcodeMachine<T> {
|
|||
this.initializer = getPluggableInitializer(language);
|
||||
}
|
||||
|
||||
protected abstract PcodeExecutorState<T> createMemoryState();
|
||||
protected abstract PcodeExecutorState<T> createSharedState();
|
||||
|
||||
protected abstract PcodeExecutorState<T> createRegisterState(PcodeThread<T> thread);
|
||||
protected abstract PcodeExecutorState<T> createLocalState(PcodeThread<T> thread);
|
||||
|
||||
protected SleighUseropLibrary<T> createThreadStubLibrary() {
|
||||
return new DefaultPcodeThread.SleighEmulationLibrary<T>(null);
|
||||
|
@ -113,12 +113,12 @@ public abstract class AbstractPcodeMachine<T> implements PcodeMachine<T> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public PcodeExecutorState<T> getMemoryState() {
|
||||
if (memoryState == null) {
|
||||
memoryState = createMemoryState();
|
||||
public PcodeExecutorState<T> getSharedState() {
|
||||
if (sharedState == null) {
|
||||
sharedState = createSharedState();
|
||||
doPluggableInitialization();
|
||||
}
|
||||
return memoryState;
|
||||
return sharedState;
|
||||
}
|
||||
|
||||
protected PcodeProgram getInject(Address address) {
|
||||
|
|
|
@ -114,10 +114,10 @@ public class DefaultPcodeThread<T> implements PcodeThread<T> {
|
|||
this.machine = machine;
|
||||
this.language = machine.language;
|
||||
this.arithmetic = machine.arithmetic;
|
||||
PcodeExecutorState<T> memoryState = machine.getMemoryState();
|
||||
PcodeExecutorState<T> registerState = machine.createRegisterState(this);
|
||||
this.state = new ThreadPcodeExecutorState<>(memoryState, registerState);
|
||||
this.decoder = createInstructionDecoder(memoryState);
|
||||
PcodeExecutorState<T> sharedState = machine.getSharedState();
|
||||
PcodeExecutorState<T> localState = machine.createLocalState(this);
|
||||
this.state = new ThreadPcodeExecutorState<>(sharedState, localState);
|
||||
this.decoder = createInstructionDecoder(sharedState);
|
||||
this.library = createUseropLibrary();
|
||||
|
||||
this.executor = createExecutor();
|
||||
|
@ -135,8 +135,8 @@ public class DefaultPcodeThread<T> implements PcodeThread<T> {
|
|||
this.reInitialize();
|
||||
}
|
||||
|
||||
protected SleighInstructionDecoder createInstructionDecoder(PcodeExecutorState<T> memoryState) {
|
||||
return new SleighInstructionDecoder(language, memoryState);
|
||||
protected SleighInstructionDecoder createInstructionDecoder(PcodeExecutorState<T> sharedState) {
|
||||
return new SleighInstructionDecoder(language, sharedState);
|
||||
}
|
||||
|
||||
protected SleighUseropLibrary<T> createUseropLibrary() {
|
||||
|
|
|
@ -54,7 +54,7 @@ public interface PcodeMachine<T> {
|
|||
PcodeThread<T> getThread(String name, boolean createIfAbsent);
|
||||
|
||||
/**
|
||||
* Get the machine's memory state
|
||||
* Get the machine's shared (memory) state
|
||||
*
|
||||
* <p>
|
||||
* The returned state will may throw {@link IllegalArgumentException} if the client requests
|
||||
|
@ -62,7 +62,7 @@ public interface PcodeMachine<T> {
|
|||
*
|
||||
* @return the memory state
|
||||
*/
|
||||
PcodeExecutorState<T> getMemoryState();
|
||||
PcodeExecutorState<T> getSharedState();
|
||||
|
||||
/**
|
||||
* Compile the given SLEIGH code for execution by a thread of this machine
|
||||
|
|
|
@ -248,7 +248,7 @@ public interface PcodeThread<T> {
|
|||
*
|
||||
* <p>
|
||||
* The memory part of this state is shared among all threads in the same machine. See
|
||||
* {@link PcodeMachine#getMemoryState()}.
|
||||
* {@link PcodeMachine#getSharedState()}.
|
||||
*
|
||||
*/
|
||||
ThreadPcodeExecutorState<T> getState();
|
||||
|
|
|
@ -6,57 +6,61 @@ import ghidra.program.model.address.AddressSpace;
|
|||
import ghidra.program.model.mem.MemBuffer;
|
||||
|
||||
public class ThreadPcodeExecutorState<T> implements PcodeExecutorState<T> {
|
||||
protected final PcodeExecutorState<T> memoryState;
|
||||
protected final PcodeExecutorState<T> registerState;
|
||||
protected final PcodeExecutorState<T> sharedState;
|
||||
protected final PcodeExecutorState<T> localState;
|
||||
|
||||
public ThreadPcodeExecutorState(PcodeExecutorState<T> memoryState,
|
||||
PcodeExecutorState<T> registerState) {
|
||||
this.memoryState = memoryState;
|
||||
this.registerState = registerState;
|
||||
public ThreadPcodeExecutorState(PcodeExecutorState<T> sharedState,
|
||||
PcodeExecutorState<T> localState) {
|
||||
this.sharedState = sharedState;
|
||||
this.localState = localState;
|
||||
}
|
||||
|
||||
protected boolean isThreadLocalSpace(AddressSpace space) {
|
||||
return space.isRegisterSpace() || space.isUniqueSpace();
|
||||
}
|
||||
|
||||
@Override
|
||||
public T longToOffset(AddressSpace space, long l) {
|
||||
if (space.isRegisterSpace()) {
|
||||
return registerState.longToOffset(space, l);
|
||||
if (isThreadLocalSpace(space)) {
|
||||
return localState.longToOffset(space, l);
|
||||
}
|
||||
else {
|
||||
return memoryState.longToOffset(space, l);
|
||||
return sharedState.longToOffset(space, l);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setVar(AddressSpace space, T offset, int size, boolean truncateAddressableUnit,
|
||||
T val) {
|
||||
if (space.isRegisterSpace()) {
|
||||
registerState.setVar(space, offset, size, truncateAddressableUnit, val);
|
||||
if (isThreadLocalSpace(space)) {
|
||||
localState.setVar(space, offset, size, truncateAddressableUnit, val);
|
||||
}
|
||||
else {
|
||||
memoryState.setVar(space, offset, size, truncateAddressableUnit, val);
|
||||
sharedState.setVar(space, offset, size, truncateAddressableUnit, val);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public T getVar(AddressSpace space, T offset, int size, boolean truncateAddressableUnit) {
|
||||
if (space.isRegisterSpace()) {
|
||||
return registerState.getVar(space, offset, size, truncateAddressableUnit);
|
||||
if (isThreadLocalSpace(space)) {
|
||||
return localState.getVar(space, offset, size, truncateAddressableUnit);
|
||||
}
|
||||
else {
|
||||
return memoryState.getVar(space, offset, size, truncateAddressableUnit);
|
||||
return sharedState.getVar(space, offset, size, truncateAddressableUnit);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public MemBuffer getConcreteBuffer(Address address) {
|
||||
assert !address.getAddressSpace().isRegisterSpace();
|
||||
return memoryState.getConcreteBuffer(address);
|
||||
assert !isThreadLocalSpace(address.getAddressSpace());
|
||||
return sharedState.getConcreteBuffer(address);
|
||||
}
|
||||
|
||||
public PcodeExecutorState<T> getMemoryState() {
|
||||
return memoryState;
|
||||
public PcodeExecutorState<T> getSharedState() {
|
||||
return sharedState;
|
||||
}
|
||||
|
||||
public PcodeExecutorState<T> getRegisterState() {
|
||||
return registerState;
|
||||
public PcodeExecutorState<T> getLocalState() {
|
||||
return localState;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue