decompiler  1.0.0
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
ghidra::MemoryPageOverlay Class Reference

Memory bank that overlays some other memory bank, using a "copy on write" behavior. More...

#include <memstate.hh>

Inheritance diagram for ghidra::MemoryPageOverlay:
ghidra::MemoryBank

Public Member Functions

 MemoryPageOverlay (AddrSpace *spc, int4 ws, int4 ps, MemoryBank *ul)
 Constructor for page overlay. More...
 
- Public Member Functions inherited from ghidra::MemoryBank
 MemoryBank (AddrSpace *spc, int4 ws, int4 ps)
 Generic constructor for a memory bank. More...
 
int4 getWordSize (void) const
 Get the number of bytes in a word for this memory bank. More...
 
int4 getPageSize (void) const
 Get the number of bytes in a page for this memory bank. More...
 
AddrSpacegetSpace (void) const
 Get the address space associated with this memory bank. More...
 
void setValue (uintb offset, int4 size, uintb val)
 Set the value of a (small) range of bytes. More...
 
uintb getValue (uintb offset, int4 size) const
 Retrieve the value encoded in a (small) range of bytes. More...
 
void setChunk (uintb offset, int4 size, const uint1 *val)
 Set values of an arbitrary sequence of bytes. More...
 
void getChunk (uintb offset, int4 size, uint1 *res) const
 Retrieve an arbitrary sequence of bytes. More...
 

Protected Member Functions

virtual void insert (uintb addr, uintb val)
 Overridden aligned word insert. More...
 
virtual uintb find (uintb addr) const
 Overridden aligned word find. More...
 
virtual void getPage (uintb addr, uint1 *res, int4 skip, int4 size) const
 Overridden getPage. More...
 
virtual void setPage (uintb addr, const uint1 *val, int4 skip, int4 size)
 Overridden setPage. More...
 

Private Attributes

MemoryBankunderlie
 Underlying memory object.
 
map< uintb, uint1 * > page
 Overlayed pages.
 

Additional Inherited Members

- Static Public Member Functions inherited from ghidra::MemoryBank
static uintb constructValue (const uint1 *ptr, int4 size, bool bigendian)
 Decode bytes to value. More...
 
static void deconstructValue (uint1 *ptr, uintb val, int4 size, bool bigendian)
 Encode value to bytes. More...
 

Detailed Description

Memory bank that overlays some other memory bank, using a "copy on write" behavior.

Pages are copied from the underlying object only when there is a write. The underlying access routines are overridden to make optimal use of this page implementation. The underlying memory bank can be a null pointer in which case, this memory bank behaves as if it were initially filled with zeros.

Constructor & Destructor Documentation

◆ MemoryPageOverlay()

ghidra::MemoryPageOverlay::MemoryPageOverlay ( AddrSpace spc,
int4  ws,
int4  ps,
MemoryBank ul 
)

Constructor for page overlay.

A page overlay memory bank needs all the parameters for a generic memory bank and it needs to know the underlying memory bank being overlayed.

Parameters
spcis the address space associated with the memory bank
wsis the number of bytes in the preferred wordsize (must be power of 2)
psis the number of bytes in a page (must be power of 2)
ulis the underlying MemoryBank

References page, and underlie.

Member Function Documentation

◆ find()

uintb ghidra::MemoryPageOverlay::find ( uintb  addr) const
protectedvirtual

Overridden aligned word find.

This derived method first looks for the aligned word in the mapped pages. If the address is not mapped, the search is forwarded to the underlying memory bank. If there is no underlying bank, zero is returned.

Parameters
addris the aligned offset of the word
Returns
the retrieved value

Implements ghidra::MemoryBank.

References ghidra::MemoryBank::constructValue(), ghidra::MemoryBank::getPageSize(), ghidra::MemoryBank::getSpace(), and ghidra::MemoryBank::getWordSize().

◆ getPage()

void ghidra::MemoryPageOverlay::getPage ( uintb  addr,
uint1 *  res,
int4  skip,
int4  size 
) const
protectedvirtual

Overridden getPage.

The desired page is looked for in the page cache. If it doesn't exist, the request is forwarded to underlying bank. If there is no underlying bank, the result buffer is filled with zeros.

Parameters
addris the aligned offset of the page
resis the pointer to where retrieved bytes should be stored
skipis the offset into the page from where bytes should be retrieved
sizeis the number of bytes to retrieve

Reimplemented from ghidra::MemoryBank.

◆ insert()

void ghidra::MemoryPageOverlay::insert ( uintb  addr,
uintb  val 
)
protectedvirtual

Overridden aligned word insert.

This derived method looks for a previously cached page of the underlying memory bank. If the cached page does not exist, it creates it and fills in its initial value by retrieving the page from the underlying bank. The new value is then written into cached page.

Parameters
addris the aligned address of the word to be written
valis the value to be written at that word

Implements ghidra::MemoryBank.

References ghidra::MemoryBank::deconstructValue(), ghidra::MemoryBank::getPageSize(), ghidra::MemoryBank::getSpace(), and ghidra::MemoryBank::getWordSize().

◆ setPage()

void ghidra::MemoryPageOverlay::setPage ( uintb  addr,
const uint1 *  val,
int4  skip,
int4  size 
)
protectedvirtual

Overridden setPage.

First, a cached version of the desired page is searched for via its address. If it doesn't exist, it is created, and its initial value is filled via the underlying bank. The bytes to be written are then copied into the cached page.

Parameters
addris the aligned offset of the page to write
valis a pointer to bytes to be written into the page
skipis the offset into the page where bytes should be written
sizeis the number of bytes to write

Reimplemented from ghidra::MemoryBank.

References ghidra::MemoryBank::getPageSize().


The documentation for this class was generated from the following files: