Package ghidra.pcode.emu

# Class ThreadPcodeExecutorState<T>

java.lang.Object
ghidra.pcode.emu.ThreadPcodeExecutorState<T>

Type Parameters:
  `T` - the type of values stored in the states

All Implemented Interfaces:
  `PcodeExecutorState<T>`, `PcodeExecutorStatePiece<T,T>`

Direct Known Subclasses:
  `JitThreadBytesPcodeExecutorState`

public class ThreadPcodeExecutorState<T> extends Object implements PcodeExecutorState<T>
A p-code executor state that multiplexes shared and thread-local states for use in a machine that models multi-threading

- ## Nested Class Summary

  ## Nested classes/interfaces inherited from interface ghidra.pcode.exec.PcodeExecutorStatePiece

  `PcodeExecutorStatePiece.Reason`

- ## Field Summary

  Fields
  Modifier and Type
  Field
  Description
  `protected final PcodeArithmetic<T>`
  `arithmetic`
  `protected final PcodeExecutorState<T>`
  `localState`
  `protected final PcodeExecutorState<T>`
  `sharedState`

- ## Constructor Summary

  Constructors
  Constructor
  Description
  `ThreadPcodeExecutorState(PcodeExecutorState<T> sharedState, PcodeExecutorState<T> localState)`
  Create a multiplexed state

- ## Method Summary

  Modifier and Type
  Method
  Description
  `void`
  `clear()`
  Erase the entire state or piece
  `ThreadPcodeExecutorState<T>`
  `fork(PcodeStateCallbacks cb)`
  Create a deep copy of this state
  `PcodeArithmetic<T>`
  `getArithmetic()`
  Get the arithmetic used to manipulate values of the type stored by this state
  `MemBuffer`
  `getConcreteBuffer(Address address, PcodeArithmetic.Purpose purpose)`
  Bind a buffer of concrete bytes at the given start address
  `Language`
  `getLanguage()`
  Get the language defining the address spaces of this state piece
  `PcodeExecutorState<T>`
  `getLocalState()`
  Get the thread-local state
  `Map<Register,T>`
  `getRegisterValues()`
  Get all register values known to this state
  `PcodeExecutorState<T>`
  `getSharedState()`
  Get the shared state
  `T`
  `getVar(AddressSpace space, long offset, int size, boolean quantize, PcodeExecutorStatePiece.Reason reason)`
  Get the value of a variable
  `T`
  `getVar(AddressSpace space, T offset, int size, boolean quantize, PcodeExecutorStatePiece.Reason reason)`
  Get the value of a variable
  `T`
  `getVarInternal(AddressSpace space, long offset, int size, PcodeExecutorStatePiece.Reason reason)`
  Get the value of a variable without issuing callbacks
  `T`
  `getVarInternal(AddressSpace space, T offset, int size, PcodeExecutorStatePiece.Reason reason)`
  Get the value of a variable without issuing callbacks
  `protected boolean`
  `isThreadLocalSpace(AddressSpace space)`
  Decide whether or not access to the given space is directed to thread-local state
  `void`
  `setVar(AddressSpace space, long offset, int size, boolean quantize, T val)`
  Set the value of a variable
  `void`
  `setVar(AddressSpace space, T offset, int size, boolean quantize, T val)`
  Set the value of a variable
  `void`
  `setVarInternal(AddressSpace space, long offset, int size, T val)`
  Set the value of a variable without issuing callbacks
  `void`
  `setVarInternal(AddressSpace space, T offset, int size, T val)`
  Set the value of a variable without issuing callbacks
  `Stream<PcodeExecutorStatePiece<?,?>>`
  `streamPieces()`
  Stream over the pieces within.

  ### Methods inherited from class java.lang.Object

  `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

  ### Methods inherited from interface ghidra.pcode.exec.PcodeExecutorState

  `getAddressArithmetic, paired`

  ### Methods inherited from interface ghidra.pcode.exec.PcodeExecutorStatePiece

  `checkRange, getNextEntryInternal, getNextEntryInternal, getVar, getVar, getVar, inspectBigInteger, inspectByte, inspectConcrete, inspectInt, inspectLong, inspectRegisterValue, inspectShort, quantizeOffset, setBigInteger, setByte, setConcrete, setInt, setLong, setRegisterValue, setRegisterValue, setShort, setVar, setVar, setVar`

- ## Field Details

  - ### sharedState

    protected final PcodeExecutorState<T> sharedState

  - ### localState

    protected final PcodeExecutorState<T> localState

  - ### arithmetic

    protected final PcodeArithmetic<T> arithmetic

- ## Constructor Details

  - ### ThreadPcodeExecutorState

    public ThreadPcodeExecutorState(PcodeExecutorState<T> sharedState, PcodeExecutorState<T> localState)
    Create a multiplexed state
    Parameters:
      `sharedState` - the shared part of the state
      `localState` - the thread-local part of the state
    See Also:
      - `DefaultPcodeThread(String, AbstractPcodeMachine)`

- ## Method Details

  - ### getLanguage

    public Language getLanguage()
    Description copied from interface: `PcodeExecutorStatePiece`
    Get the language defining the address spaces of this state piece
    Specified by:
      `getLanguage` in interface `PcodeExecutorStatePiece<T,T>`
    Returns:
      the language

  - ### getArithmetic

    public PcodeArithmetic<T> getArithmetic()
    Description copied from interface: `PcodeExecutorStatePiece`
    Get the arithmetic used to manipulate values of the type stored by this state
    Specified by:
      `getArithmetic` in interface `PcodeExecutorStatePiece<T,T>`
    Returns:
      the arithmetic

  - ### streamPieces

    public Stream<PcodeExecutorStatePiece<?,?>> streamPieces()
    Stream over the pieces within.

    If this piece is not a composition of others, then simply stream this piece in a singleton. Otherwise, stream the component pieces. (Do not include the composition itself, just the component pieces.)

    This will only include the pieces in the thread's local state.

    Specified by:
      `streamPieces` in interface `PcodeExecutorStatePiece<T,T>`
    Returns:
      the stream

  - ### fork

    public ThreadPcodeExecutorState<T> fork(PcodeStateCallbacks cb)
    Description copied from interface: `PcodeExecutorStatePiece`
    Create a deep copy of this state
    Specified by:
      `fork` in interface `PcodeExecutorState<T>`
    Specified by:
      `fork` in interface `PcodeExecutorStatePiece<T,T>`
    Parameters:
      `cb` - callbacks to receive emulation events
    Returns:
      the copy

  - ### isThreadLocalSpace

    protected boolean isThreadLocalSpace(AddressSpace space)
    Decide whether or not access to the given space is directed to thread-local state
    Parameters:
      `space` - the space
    Returns:
      true for thread-local state, false for shared state

  - ### setVar

    public void setVar(AddressSpace space, T offset, int size, boolean quantize, T val)
    Description copied from interface: `PcodeExecutorStatePiece`
    Set the value of a variable
    Specified by:
      `setVar` in interface `PcodeExecutorStatePiece<T,T>`
    Parameters:
      `space` - the address space
      `offset` - the offset within the space
      `size` - the size of the variable
      `quantize` - true to quantize to the language's "addressable unit"
      `val` - the value

  - ### setVarInternal

    public void setVarInternal(AddressSpace space, T offset, int size, T val)
    Description copied from interface: `PcodeExecutorStatePiece`
    Set the value of a variable without issuing callbacks
    Specified by:
      `setVarInternal` in interface `PcodeExecutorStatePiece<T,T>`
    Parameters:
      `space` - the address space
      `offset` - the offset within the space
      `size` - the size of the variable
      `val` - the value

  - ### setVar

    public void setVar(AddressSpace space, long offset, int size, boolean quantize, T val)
    Description copied from interface: `PcodeExecutorStatePiece`
    Set the value of a variable
    Specified by:
      `setVar` in interface `PcodeExecutorStatePiece<T,T>`
    Parameters:
      `space` - the address space
      `offset` - the offset within the space
      `size` - the size of the variable
      `quantize` - true to quantize to the language's "addressable unit"
      `val` - the value

  - ### setVarInternal

    public void setVarInternal(AddressSpace space, long offset, int size, T val)
    Description copied from interface: `PcodeExecutorStatePiece`
    Set the value of a variable without issuing callbacks
    Specified by:
      `setVarInternal` in interface `PcodeExecutorStatePiece<T,T>`
    Parameters:
      `space` - the address space
      `offset` - the offset within the space
      `size` - the size of the variable
      `val` - the value

  - ### getVar

    public T getVar(AddressSpace space, T offset, int size, boolean quantize, PcodeExecutorStatePiece.Reason reason)
    Description copied from interface: `PcodeExecutorStatePiece`
    Get the value of a variable
    Specified by:
      `getVar` in interface `PcodeExecutorStatePiece<T,T>`
    Parameters:
      `space` - the address space
      `offset` - the offset within the space
      `size` - the size of the variable
      `quantize` - true to quantize to the language's "addressable unit"
      `reason` - the reason for reading the variable
    Returns:
      the value

  - ### getVarInternal

    public T getVarInternal(AddressSpace space, T offset, int size, PcodeExecutorStatePiece.Reason reason)
    Description copied from interface: `PcodeExecutorStatePiece`
    Get the value of a variable without issuing callbacks
    Specified by:
      `getVarInternal` in interface `PcodeExecutorStatePiece<T,T>`
    Parameters:
      `space` - the address space
      `offset` - the offset within the space
      `size` - the size of the variable
      `reason` - the reason for reading the variable
    Returns:
      the value

  - ### getVar

    public T getVar(AddressSpace space, long offset, int size, boolean quantize, PcodeExecutorStatePiece.Reason reason)
    Description copied from interface: `PcodeExecutorStatePiece`
    Get the value of a variable

    This method is typically used for reading memory variables.

    Specified by:
      `getVar` in interface `PcodeExecutorStatePiece<T,T>`
    Parameters:
      `space` - the address space
      `offset` - the offset within the space
      `size` - the size of the variable
      `quantize` - true to quantize to the language's "addressable unit"
      `reason` - the reason for reading the variable
    Returns:
      the value

  - ### getVarInternal

    public T getVarInternal(AddressSpace space, long offset, int size, PcodeExecutorStatePiece.Reason reason)
    Description copied from interface: `PcodeExecutorStatePiece`
    Get the value of a variable without issuing callbacks
    Specified by:
      `getVarInternal` in interface `PcodeExecutorStatePiece<T,T>`
    Parameters:
      `space` - the address space
      `offset` - the offset within the space
      `size` - the size of the variable
      `reason` - the reason for reading the variable
    Returns:
      the value

  - ### getRegisterValues

    public Map<Register,T> getRegisterValues()
    Description copied from interface: `PcodeExecutorStatePiece`
    Get all register values known to this state

    When the state acts as a cache, it should only return those cached.

    Specified by:
      `getRegisterValues` in interface `PcodeExecutorStatePiece<T,T>`
    Returns:
      a map of registers and their values

  - ### getConcreteBuffer

    public MemBuffer getConcreteBuffer(Address address, PcodeArithmetic.Purpose purpose)
    Description copied from interface: `PcodeExecutorStatePiece`
    Bind a buffer of concrete bytes at the given start address
    Specified by:
      `getConcreteBuffer` in interface `PcodeExecutorStatePiece<T,T>`
    Parameters:
      `address` - the start address
      `purpose` - the reason why the emulator needs a concrete value
    Returns:
      a buffer

  - ### getSharedState

    public PcodeExecutorState<T> getSharedState()
    Get the shared state
    Returns:
      the shared state

  - ### getLocalState

    public PcodeExecutorState<T> getLocalState()
    Get the thread-local state
    Returns:
      the thread-local state

  - ### clear

    public void clear()
    Erase the entire state or piece

    This is generally only useful when the state is itself a cache to another object. This will ensure the state is reading from that object rather than a stale cache. If this is not a cache, this could in fact clear the whole state, and the machine using it will be left in the dark.

    This will only clear the thread's local state, lest we invoke clear on the shared state for every thread. Instead, if necessary, the machine should clear its shared state then clear each thread's local state.

    Specified by:
      `clear` in interface `PcodeExecutorStatePiece<T,T>`