Class AbstractLongOffsetPcodeExecutorStatePiece<A,T,S>

java.lang.Object
ghidra.pcode.exec.AbstractLongOffsetPcodeExecutorStatePiece<A,T,S>
Type Parameters:
A - the type used to address contents, convertible to and from long
T - the type of values stored
S - the type of an execute state space, internally associated with an address space
All Implemented Interfaces:
PcodeExecutorStatePiece<A,T>
Direct Known Subclasses:
AbstractBytesPcodeExecutorStatePiece, AddressesReadTracePcodeExecutorStatePiece, TaintPcodeExecutorStatePiece, TraceMemoryStatePcodeExecutorStatePiece

public abstract class AbstractLongOffsetPcodeExecutorStatePiece<A,T,S> extends Object implements PcodeExecutorStatePiece<A,T>
An abstract executor state piece which internally uses long to address contents

This also provides an internal mechanism for breaking the piece down into the spaces defined by a language. It also provides for the special treatment of the unique space.

  • Field Details

  • Constructor Details

    • AbstractLongOffsetPcodeExecutorStatePiece

      public AbstractLongOffsetPcodeExecutorStatePiece(Language language, PcodeArithmetic<A> addressArithmetic, PcodeArithmetic<T> arithmetic, PcodeStateCallbacks cb)
      Construct a state piece for the given language and arithmetic
      Parameters:
      language - the language (used for its memory model)
      addressArithmetic - an arithmetic used to generate default values of A
      arithmetic - an arithmetic used to generate default values of T. It must be able to derive concrete sizes, i.e., PcodeArithmetic.sizeOf(Object) must always return the correct value.
      cb - callbacks to receive emulation events
  • Method Details

    • forkMap

      protected static <S> void forkMap(Map<AddressSpace,S> into, Map<AddressSpace,S> from, Function<S,S> forker)
    • 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<A,T>
      Returns:
      the language
    • getAddressArithmetic

      public PcodeArithmetic<A> getAddressArithmetic()
      Description copied from interface: PcodeExecutorStatePiece
      Get the arithmetic used to manipulate addresses of the type used by this state
      Specified by:
      getAddressArithmetic in interface PcodeExecutorStatePiece<A,T>
      Returns:
      the address (or offset) arithmetic
    • 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<A,T>
      Returns:
      the arithmetic
    • streamPieces

      public Stream<PcodeExecutorStatePiece<?,?>> streamPieces()
      Description copied from interface: PcodeExecutorStatePiece
      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.)

      Specified by:
      streamPieces in interface PcodeExecutorStatePiece<A,T>
      Returns:
      the stream
    • setUnique

      protected void setUnique(long offset, int size, T val, PcodeStateCallbacks cb)
      Set a value in the unique space

      Some state pieces treat unique values in a way that merits a separate implementation. This permits the standard path to be overridden.

      Parameters:
      offset - the offset in unique space to store the value
      size - the number of bytes to write (the size of the value)
      val - the value to store
      cb - callbacks to receive emulation events
    • getUnique

      protected T getUnique(long offset, int size, PcodeExecutorStatePiece.Reason reason, PcodeStateCallbacks cb)
      Get a value from the unique space Some state pieces treat unique values in a way that merits a separate implementation. This permits the standard path to be overridden.
      Parameters:
      offset - the offset in unique space to get the value
      size - the number of bytes to read (the size of the value)
      reason - the reason for reading state
      cb - callbacks to receive emulation events
      Returns:
      the read value
    • getForSpace

      protected abstract S getForSpace(AddressSpace space, boolean toWrite)
      Get the internal space for the given address space
      Parameters:
      space - the address space
      toWrite - in case internal spaces are generated lazily, this indicates the space must be present, because it is going to be written to.
      Returns:
      the space, or null
    • setInSpace

      protected abstract void setInSpace(S space, long offset, int size, T val, PcodeStateCallbacks cb)
      Set a value in the given space
      Parameters:
      space - the address space
      offset - the offset within the space
      size - the number of bytes to write (the size of the value)
      val - the value to store
      cb - callbacks to receive emulation events
    • getFromSpace

      protected abstract T getFromSpace(S space, long offset, int size, PcodeExecutorStatePiece.Reason reason, PcodeStateCallbacks cb)
      Get a value from the given space
      Parameters:
      space - the address space
      offset - the offset within the space
      size - the number of bytes to read (the size of the value)
      reason - the reason for reading state
      cb - callbacks to receive emulation events
      Returns:
      the read value
    • getFromNullSpace

      protected T getFromNullSpace(int size, PcodeExecutorStatePiece.Reason reason, PcodeStateCallbacks cb)
      In case spaces are generated lazily, and we're reading from a space that doesn't yet exist, "read" a default value.

      By default, the returned value is 0, which should be reasonable for all implementations.

      Parameters:
      size - the number of bytes to read (the size of the value)
      reason - the reason for reading state
      cb - callbacks to receive emulation events
      Returns:
      the default value
    • setVarInternal

      protected void setVarInternal(AddressSpace space, long offset, int size, boolean quantize, T val, PcodeStateCallbacks cb)
    • setVar

      public void setVar(AddressSpace space, A offset, int size, boolean quantize, T val)
      Description copied from interface: PcodeExecutorStatePiece
      Set the value of a variable
      Specified by:
      setVar in interface PcodeExecutorStatePiece<A,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, A 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<A,T>
      Parameters:
      space - the address space
      offset - the offset within the space
      size - the size of the variable
      val - the value
    • checkSize

      protected T checkSize(int size, T val)
      Check that the size of the value matches that given

      Extensions may override this and do nothing when the abstract type has no defined size

      Parameters:
      size - the size in bytes
      val - the value
      Returns:
      the value, possibly adjusted
    • 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<A,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<A,T>
      Parameters:
      space - the address space
      offset - the offset within the space
      size - the size of the variable
      val - the value
    • getVarInternal

      protected T getVarInternal(AddressSpace space, long offset, int size, boolean quantize, PcodeExecutorStatePiece.Reason reason, PcodeStateCallbacks cb)
    • getVar

      public T getVar(AddressSpace space, A 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<A,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, A 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<A,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<A,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<A,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
    • getRegisterValuesFromSpace

      protected abstract Map<Register,T> getRegisterValuesFromSpace(S s, List<Register> registers)
      Can the given space for register values, as in getRegisterValues()
      Parameters:
      s - the space to scan
      registers - the registers known to be in the corresponding address space
      Returns:
      the map of registers to values
    • 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<A,T>
      Returns:
      a map of registers and their values