Class MemoryBank

java.lang.Object
ghidra.pcode.memstate.MemoryBank
Direct Known Subclasses:
MemoryImage, MemoryPageBank, UniqueMemoryBank

public abstract class MemoryBank extends Object
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected final MemoryFaultHandler
     
  • Constructor Summary

    Constructors
    Constructor
    Description
    MemoryBank(AddressSpace spc, boolean isBigEndian, int ps, MemoryFaultHandler faultHandler)
    A MemoryBank must be associated with a specific address space, have a preferred or natural pagesize.
  • Method Summary

    Modifier and Type
    Method
    Description
    static long
    constructValue(byte[] ptr, int offset, int size, boolean bigendian)
    This is a static convenience routine for decoding a value from a sequence of bytes depending on the desired endianness
    static void
    deconstructValue(byte[] ptr, int offset, long val, int size, boolean bigendian)
    This is a static convenience routine for encoding bytes from a given value, depending on the desired endianness
    int
    getChunk(long addrOffset, int size, byte[] res, boolean stopOnUnintialized)
    This is the most general method for reading a sequence of bytes from the memory bank.
    int
     
     
    protected abstract MemoryPage
    getPage(long addr)
     
    int
    A MemoryBank is instantiated with a natural page size.
     
    boolean
     
    void
    setChunk(long offset, int size, byte[] val)
    This the most general method for writing a sequence of bytes into the memory bank.
    void
    setInitialized(long offset, int size, boolean initialized)
    This method allows ranges of bytes to marked as initialized or not.
    protected abstract void
    setPage(long addr, byte[] val, int skip, int size, int bufOffset)
    This routine writes data only to a single page of the memory bank.
    protected abstract void
    setPageInitialized(long addr, boolean initialized, int skip, int size, int bufOffset)
    This routine marks a range within a single page of the memory bank as initialized or uninitialized.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

    • MemoryBank

      public MemoryBank(AddressSpace spc, boolean isBigEndian, int ps, MemoryFaultHandler faultHandler)
      A MemoryBank must be associated with a specific address space, have a preferred or natural pagesize. The pagesize must be a power of 2.
      Parameters:
      spc - is the associated address space
      isBigEndian - memory endianness
      ps - ps is the number of bytes in a page (must be a power of 2)
      faultHandler - memory fault handler
  • Method Details

    • getMemoryFaultHandler

      public MemoryFaultHandler getMemoryFaultHandler()
      Returns:
      memory fault handler (may be null)
    • isBigEndian

      public boolean isBigEndian()
      Returns:
      true if memory bank is big endian
    • getPageSize

      public int getPageSize()
      A MemoryBank is instantiated with a natural page size. Requests for large chunks of data may be broken down into units of this size.
      Returns:
      the number of bytes in a page.
    • getInitializedMaskSize

      public int getInitializedMaskSize()
      Returns:
      the size of a page initialized mask in bytes. Each bit within the mask corresponds to a data byte within a page.
    • getSpace

      public AddressSpace getSpace()
      Returns:
      the AddressSpace associated with this bank.
    • getPage

      protected abstract MemoryPage getPage(long addr)
    • setPage

      protected abstract void setPage(long addr, byte[] val, int skip, int size, int bufOffset)
      This routine writes data only to a single page of the memory bank. Bytes need not be written to the exact start of the page, but all bytes must be written to only one page when using this routine. A page is a fixed number of bytes, and the address of a page is always aligned based on this size. This routine may be overridden for a page based implementation of the MemoryBank. The default implementation writes the page as a sequence of aligned words, using the insert method.
      Parameters:
      addr - is the aligned offset of the desired page
      val - is a pointer to the bytes to be written into the page
      skip - is the offset into the page where bytes will be written
      size - is the number of bytes to be written
      bufOffset - the offset in val from which to get the bytes
    • setPageInitialized

      protected abstract void setPageInitialized(long addr, boolean initialized, int skip, int size, int bufOffset)
      This routine marks a range within a single page of the memory bank as initialized or uninitialized. A page is a fixed number of bytes, and the address of a page is always aligned based on this size. This routine may be overridden for a page based implementation of the MemoryBank. The default implementation writes the page as a sequence of aligned words, using the insert method.
      Parameters:
      addr - is the aligned offset of the desired page
      initialized - true if range should be marked as initialized, false if uninitialized
      skip - is the offset into the page where bytes will be written
      size - is the number of bytes to be written
      bufOffset - the offset in val from which to get the bytes
    • setChunk

      public void setChunk(long offset, int size, byte[] val)
      This the most general method for writing a sequence of bytes into the memory bank. The initial offset and page writes will be wrapped within the address space.
      Parameters:
      offset - is the start of the byte range to be written. This offset will be wrapped within the space
      size - is the number of bytes to write
      val - is a pointer to the sequence of bytes to be written into the bank
    • setInitialized

      public void setInitialized(long offset, int size, boolean initialized)
      This method allows ranges of bytes to marked as initialized or not. There is no restriction on the offset to write to or the number of bytes to be written, except that the range must be contained in the address space.
      Parameters:
      offset - is the start of the byte range to be written
      size - is the number of bytes to write
      initialized - indicates if the range should be marked as initialized or not
    • getChunk

      public int getChunk(long addrOffset, int size, byte[] res, boolean stopOnUnintialized)
      This is the most general method for reading a sequence of bytes from the memory bank. There is no restriction on the offset or the number of bytes to read, except that the range must be contained in the address space.
      Parameters:
      addrOffset - is the start of the byte range to read
      size - is the number of bytes to read
      res - is a pointer to where the retrieved bytes should be stored
      stopOnUnintialized - if true a partial read is permitted and returned size may be smaller than size requested if uninitialized data is encountered.
      Returns:
      number of bytes actually read
    • constructValue

      public static long constructValue(byte[] ptr, int offset, int size, boolean bigendian)
      This is a static convenience routine for decoding a value from a sequence of bytes depending on the desired endianness
      Parameters:
      ptr - is the pointer to the bytes to decode
      offset - a fixed offset from ptr used during decode
      size - is the number of bytes
      bigendian - is true if the bytes are encoded in big endian form
      Returns:
      the decoded value
    • deconstructValue

      public static void deconstructValue(byte[] ptr, int offset, long val, int size, boolean bigendian)
      This is a static convenience routine for encoding bytes from a given value, depending on the desired endianness
      Parameters:
      ptr - is a pointer to the location to write the encoded bytes
      offset - a fixed offset from ptr to where to write the bytes
      val - is the value to be encoded
      size - is the number of bytes to encode
      bigendian - is true if a big endian encoding is desired