decompiler  1.0.0
Public Member Functions | Protected Member Functions | Private Attributes | List of all members
AddrSpaceManager Class Reference

A manager for different address spaces. More...

#include <translate.hh>

Inheritance diagram for AddrSpaceManager:
Architecture Translate ArchitectureGhidra SleighArchitecture GhidraTranslate SleighBase BfdArchitecture RawBinaryArchitecture XmlArchitecture Sleigh

Public Member Functions

 AddrSpaceManager (void)
 Construct an empty address space manager. More...
 
virtual ~AddrSpaceManager (void)
 Destroy the manager. More...
 
char assignShortcut (spacetype tp) const
 Select a shortcut character for a new space. More...
 
int4 getDefaultSize (void) const
 Get size of addresses for the default space. More...
 
AddrSpacegetSpaceByName (const string &nm) const
 Get address space by name. More...
 
AddrSpacegetSpaceByShortcut (char sc) const
 Get address space from its shortcut. More...
 
AddrSpacegetIopSpace (void) const
 Get the internal pcode op space. More...
 
AddrSpacegetFspecSpace (void) const
 Get the internal callspec space. More...
 
AddrSpacegetJoinSpace (void) const
 Get the joining space. More...
 
AddrSpacegetStackSpace (void) const
 Get the stack space for this processor. More...
 
AddrSpacegetUniqueSpace (void) const
 Get the temporary register space for this processor. More...
 
AddrSpacegetDefaultSpace (void) const
 Get the default address space of this processor. More...
 
AddrSpacegetConstantSpace (void) const
 Get the constant space. More...
 
Address getConstant (uintb val) const
 Get a constant encoded as an Address. More...
 
Address createConstFromSpace (AddrSpace *spc) const
 Create a constant address encoding an address space. More...
 
Address resolveConstant (AddrSpace *spc, uintb val, int4 sz, const Address &point) const
 Resolve native constant to address.
 
int4 numSpaces (void) const
 Get the number of address spaces for this processor. More...
 
AddrSpacegetSpace (int4 i) const
 Get an address space via its index. More...
 
AddrSpacegetNextSpaceInOrder (AddrSpace *spc) const
 Get the next contiguous address space. More...
 
JoinRecordfindAddJoin (const vector< VarnodeData > &pieces, uint4 logicalsize)
 Get (or create) JoinRecord for pieces. More...
 
JoinRecordfindJoin (uintb offset) const
 Find JoinRecord for offset in the join space. More...
 
void setDeadcodeDelay (int4 spcnum, int4 delaydelta)
 Set the deadcodedelay for a specific space. More...
 
void truncateSpace (const TruncationTag &tag)
 Mark a space as truncated from its original size. More...
 
Address constructFloatExtensionAddress (const Address &realaddr, int4 realsize, int4 logicalsize)
 Build a logically lower precision storage location for a bigger floating point register. More...
 
Address constructJoinAddress (const Translate *translate, const Address &hiaddr, int4 hisz, const Address &loaddr, int4 losz)
 Build a logical whole from register pairs. More...
 

Protected Member Functions

AddrSpacerestoreXmlSpace (const Element *el, const Translate *trans)
 Add a space to the model based an on XML tag. More...
 
void restoreXmlSpaces (const Element *el, const Translate *trans)
 Restore address spaces in the model from an XML tag. More...
 
void setDefaultSpace (int4 index)
 Set the default address space. More...
 
void setReverseJustified (AddrSpace *spc)
 Set reverse justified property on this space. More...
 
void insertSpace (AddrSpace *spc)
 Add a new address space to the model. More...
 
void copySpaces (const AddrSpaceManager *op2)
 Copy spaces from another manager. More...
 
void addSpacebasePointer (SpacebaseSpace *basespace, const VarnodeData &ptrdata, int4 truncSize, bool stackGrowth)
 Set the base register of a spacebase space. More...
 
void insertResolver (AddrSpace *spc, AddressResolver *rsolv)
 Override the base resolver for a space. More...
 

Private Attributes

vector< AddrSpace * > baselist
 Every space we know about for this architecture.
 
vector< AddressResolver * > resolvelist
 Special constant resolvers.
 
AddrSpaceconstantspace
 Quick reference to constant space.
 
AddrSpacedefaultspace
 Generally primary RAM, where assembly pointers point to.
 
AddrSpaceiopspace
 Space for internal pcode op pointers.
 
AddrSpacefspecspace
 Space for internal callspec pointers.
 
AddrSpacejoinspace
 Space for unifying split variables.
 
AddrSpacestackspace
 Stack space associated with processor.
 
AddrSpaceuniqspace
 Temporary space associated with processor.
 
uintb joinallocate
 Next offset to be allocated in join space.
 
set< JoinRecord *, JoinRecordComparesplitset
 Different splits that have been defined in join space.
 
vector< JoinRecord * > splitlist
 JoinRecords indexed by join address.
 

Detailed Description

A manager for different address spaces.

Allow creation, lookup by name, lookup by shortcut, lookup by name, and iteration over address spaces

Constructor & Destructor Documentation

◆ AddrSpaceManager()

AddrSpaceManager::AddrSpaceManager ( void  )

Construct an empty address space manager.

Initialize manager containing no address spaces. All the cached space slots are set to null.

References constantspace, defaultspace, fspecspace, iopspace, joinallocate, joinspace, stackspace, and uniqspace.

◆ ~AddrSpaceManager()

AddrSpaceManager::~AddrSpaceManager ( void  )
virtual

Destroy the manager.

Base destructor class, cleans up AddrSpace pointers which must be explicited created via new

References baselist, AddrSpace::refcount, resolvelist, and splitlist.

Member Function Documentation

◆ addSpacebasePointer()

void AddrSpaceManager::addSpacebasePointer ( SpacebaseSpace basespace,
const VarnodeData ptrdata,
int4  truncSize,
bool  stackGrowth 
)
protected

Set the base register of a spacebase space.

Perform the privileged act of associating a base register with an existing virtual space

Parameters
basespaceis the virtual space
ptrdatais the location data for the base register
truncSizeis the size of the space covered by the base register
stackGrowthis true if the stack grows "normally" towards address 0

References SpacebaseSpace::setBaseRegister().

Referenced by Architecture::addSpacebase().

◆ assignShortcut()

char AddrSpaceManager::assignShortcut ( spacetype  tp) const

Select a shortcut character for a new space.

Assign a shortcut character to an address space This routine makes use of the desired type of the new space and info about shortcuts for spaces that already exist to pick a unique and consistent character. This is currently invoked by the AddrSpace initialization process.

Parameters
tpis the type of the new space
Returns
the shortcut character

References baselist, IPTR_CONSTANT, IPTR_FSPEC, IPTR_INTERNAL, IPTR_IOP, IPTR_JOIN, IPTR_PROCESSOR, and IPTR_SPACEBASE.

Referenced by AddrSpace::assignShortcut().

◆ constructFloatExtensionAddress()

Address AddrSpaceManager::constructFloatExtensionAddress ( const Address realaddr,
int4  realsize,
int4  logicalsize 
)

Build a logically lower precision storage location for a bigger floating point register.

This handles the situation where we need to find a logical address to hold the lower precision floating-point value that is stored in a bigger register If the logicalsize (precision) requested matches the -realsize- of the register just return the real address. Otherwise construct a join address to hold the logical value

Parameters
realaddris the address of the real floating-point register
realsizeis the size of the real floating-point register
logicalsizeis the size (lower precision) size of the logical value

References findAddJoin(), VarnodeData::getAddr(), Address::getOffset(), Address::getSpace(), and JoinRecord::getUnified().

Referenced by ParamEntry::getAddrBySlot().

◆ constructJoinAddress()

Address AddrSpaceManager::constructJoinAddress ( const Translate translate,
const Address hiaddr,
int4  hisz,
const Address loaddr,
int4  losz 
)

Build a logical whole from register pairs.

This handles the common case, of trying to find a join address given a high location and a low location. This may not return an address in the join address space. It checks for the case where the two pieces are contiguous locations in a mappable space, in which case it just returns the containing address

Parameters
translateis the Translate object used to find registers
hiaddris the address of the most significant piece to be joined
hiszis the size of the most significant piece
loaddris the address of the least significant piece
loszis the size of the least significant piece
Returns
an address representing the start of the joined range

References findAddJoin(), VarnodeData::getAddr(), getDefaultSpace(), Address::getOffset(), Translate::getRegisterName(), Address::getSpace(), AddrSpace::getType(), JoinRecord::getUnified(), IPTR_PROCESSOR, IPTR_SPACEBASE, Address::isBigEndian(), and Address::isContiguous().

Referenced by FuncCallSpecs::buildOutputFromTrials(), and ActionReturnRecovery::buildReturnOutput().

◆ copySpaces()

void AddrSpaceManager::copySpaces ( const AddrSpaceManager op2)
protected

Copy spaces from another manager.

Different managers may need to share the same spaces. I.e. if different programs being analyzed share the same processor. This routine pulls in a reference of every space in -op2- in order to manage it from within -this-

Parameters
op2is a pointer to space manager being copied

References baselist, getDefaultSpace(), AddrSpace::getIndex(), insertSpace(), and setDefaultSpace().

Referenced by Architecture::restoreFromSpec().

◆ createConstFromSpace()

Address AddrSpaceManager::createConstFromSpace ( AddrSpace spc) const
inline

Create a constant address encoding an address space.

This routine is used to encode a pointer to an address space as a constant Address, for use in LOAD and STORE operations. This is used internally and is slightly more efficient than storing the formal index of the space param spc is the space pointer to be encoded

Returns
the encoded Address

References constantspace.

Referenced by Funcdata::newVarnodeSpace().

◆ findAddJoin()

JoinRecord * AddrSpaceManager::findAddJoin ( const vector< VarnodeData > &  pieces,
uint4  logicalsize 
)

Get (or create) JoinRecord for pieces.

Given a list of memory locations, the pieces, either find a pre-existing JoinRecord or create a JoinRecord that represents the logical joining of the pieces.

Parameters
piecesif the list memory locations to be joined
logicalsizeof a single piece join, or zero
Returns
a pointer to the JoinRecord

References joinallocate, joinspace, VarnodeData::offset, JoinRecord::pieces, VarnodeData::size, VarnodeData::space, splitlist, splitset, and JoinRecord::unified.

Referenced by constructFloatExtensionAddress(), constructJoinAddress(), JoinSpace::read(), and JoinSpace::restoreXmlAttributes().

◆ findJoin()

JoinRecord * AddrSpaceManager::findJoin ( uintb  offset) const

Find JoinRecord for offset in the join space.

Given a specific offset into the join address space, recover the JoinRecord that lists the pieces corresponding to that offset. The offset must originally have come from a JoinRecord returned by findAddJoin, otherwise this method throws an exception.

Parameters
offsetis an offset into the join space
Returns
the JoinRecord for that offset

References VarnodeData::offset, splitlist, and JoinRecord::unified.

Referenced by Scope::addMap(), RulePullsubMulti::buildSubpiece(), JoinSpace::printRaw(), Heritage::processJoins(), ParamEntry::resolveJoin(), and JoinSpace::saveXmlAttributes().

◆ getConstant()

Address AddrSpaceManager::getConstant ( uintb  val) const
inline

Get a constant encoded as an Address.

This routine encodes a specific value as a constant address. I.e. the address space of the resulting Address will be the constant space, and the offset will be the value.

Parameters
valis the constant value to encode
Returns
the constant address

References constantspace.

Referenced by RuleCollapseConstants::applyOp(), and Funcdata::newConstant().

◆ getConstantSpace()

AddrSpace * AddrSpaceManager::getConstantSpace ( void  ) const
inline

Get the constant space.

Pcode represents constant values within an operation as offsets within a special constant address space. (See ConstantSpace)

Returns
a pointer to the constant space

References constantspace.

Referenced by ActionConstantPtr::apply(), Sleigh::initialize(), Sleigh::oneInstruction(), PcodeEmit::restoreXmlOp(), and PcodeEmit::unpackVarnodeData().

◆ getDefaultSize()

int4 AddrSpaceManager::getDefaultSize ( void  ) const
inline

Get size of addresses for the default space.

Return the size of addresses for the processor's official default space. This space is usually the main RAM databus.

Returns
the size of an address in bytes

References defaultspace, and AddrSpace::getAddrSize().

Referenced by ActionParamDouble::apply(), Varnode::printRawNoMarkup(), and Architecture::restoreFromSpec().

◆ getDefaultSpace()

AddrSpace * AddrSpaceManager::getDefaultSpace ( void  ) const
inline

Get the default address space of this processor.

Most processors have a main address bus, on which the bulk of the processor's RAM is mapped. Everything referenced with this address bus should be modeled in pcode with a single address space, referred to as the default space.

Returns
a pointer to the default space

References defaultspace.

Referenced by ActionConstantPtr::apply(), ActionPrototypeTypes::apply(), RulePtrFlow::applyOp(), ParamListStandard::assignMap(), ParamListStandardOut::assignMap(), ExecutablePcode::build(), constructJoinAddress(), copySpaces(), RawBinaryArchitecture::postSpecFile(), BfdArchitecture::postSpecFile(), ActionInferTypes::propagateTypeEdge(), PrintC::pushPtrCharConstant(), PrintC::pushPtrCodeConstant(), VarnodeData::restoreXml(), Range::restoreXml(), RulePtrFlow::RulePtrFlow(), and SleighBase::saveXml().

◆ getFspecSpace()

AddrSpace * AddrSpaceManager::getFspecSpace ( void  ) const
inline

Get the internal callspec space.

There is a special address space reserved for encoding pointers to the FuncCallSpecs object as addresses. This allows direct pointers to be hidden within an operation, when manipulating pcode internally. (See FspecSpace)

Returns
a pointer to the address space

References fspecspace.

Referenced by Funcdata::newVarnodeCallSpecs().

◆ getIopSpace()

AddrSpace * AddrSpaceManager::getIopSpace ( void  ) const
inline

Get the internal pcode op space.

There is a special address space reserved for encoding pointers to pcode operations as addresses. This allows a direct pointer to be hidden within an operation, when manipulating pcode internally. (See IopSpace)

Returns
a pointer to the address space

References iopspace.

Referenced by Funcdata::newVarnodeIop().

◆ getJoinSpace()

AddrSpace * AddrSpaceManager::getJoinSpace ( void  ) const
inline

Get the joining space.

There is a special address space reserved for providing a logical contiguous memory location for variables that are really split between two physical locations. This allows the the decompiler to work with the logical value. (See JoinSpace)

Returns
a pointer to the address space

References joinspace.

Referenced by Heritage::processJoins().

◆ getNextSpaceInOrder()

AddrSpace * AddrSpaceManager::getNextSpaceInOrder ( AddrSpace spc) const

Get the next contiguous address space.

Get the next space in the absolute order of addresses. This ordering is determined by the AddrSpace index.

Parameters
spcis the pointer to the space being queried
Returns
the pointer to the next space in absolute order

References baselist, and AddrSpace::getIndex().

Referenced by VarnodeBank::endLoc(), and Range::getLastAddrOpen().

◆ getSpace()

AddrSpace * AddrSpaceManager::getSpace ( int4  i) const
inline

Get an address space via its index.

This retrieves a specific address space via its formal index. All spaces have an index, and in conjunction with the numSpaces method, this method can be used to iterate over all spaces.

Parameters
iis the index of the address space
Returns
a pointer to the desired space

References baselist.

Referenced by ActionNameVars::apply(), ActionDeadCode::apply(), Override::applyDeadCodeDelay(), ConditionalExecution::buildHeritageArray(), Heritage::buildInfoList(), Override::generateDeadcodeDelayMessage(), Architecture::getSpaceBySpacebase(), Architecture::globalify(), Heritage::heritage(), GhidraTranslate::oneInstruction(), Architecture::parseGlobal(), Override::printRaw(), SleighBase::saveXml(), Override::saveXml(), Funcdata::spacebase(), and PcodeEmit::unpackVarnodeData().

◆ getSpaceByName()

AddrSpace * AddrSpaceManager::getSpaceByName ( const string &  nm) const

Get address space by name.

All address spaces have a unique name associated with them. This routine retrieves the AddrSpace object based on the desired name.

Parameters
nmis the name of the address space
Returns
a pointer to the AddrSpace object

References baselist.

Referenced by LoadImageXml::open(), Architecture::parseDeadcodeDelay(), Architecture::parseSpacebase(), Architecture::parseStackPointer(), VarnodeData::restoreXml(), Override::restoreXml(), ScopeLocal::restoreXml(), SpacebaseSpace::restoreXml(), Range::restoreXml(), SegmentOp::restoreXml(), OverlaySpace::restoreXml(), JoinSpace::restoreXmlAttributes(), PcodeEmit::restoreXmlOp(), restoreXmlSpaces(), and truncateSpace().

◆ getSpaceByShortcut()

AddrSpace * AddrSpaceManager::getSpaceByShortcut ( char  sc) const

Get address space from its shortcut.

All address spaces have a unique shortcut (ASCII) character assigned to them. This routine retrieves an AddrSpace object given a specific shortcut.

Parameters
scis the shortcut character
Returns
a pointer to an AddrSpace

References baselist.

Referenced by JoinSpace::read().

◆ getStackSpace()

AddrSpace * AddrSpaceManager::getStackSpace ( void  ) const
inline

Get the stack space for this processor.

Most processors have registers and instructions that are reserved for implementing a stack. In the pcode translation, these are translated into locations and operations on a dedicated stack address space. (See SpacebaseSpace)

Returns
a pointer to the stack space

References stackspace.

Referenced by ActionPrototypeTypes::apply(), ActionActiveParam::apply(), ProtoModel::defaultLocalRange(), ProtoModel::defaultParamRange(), Funcdata::Funcdata(), ProtoModel::restoreXml(), and universal_action().

◆ getUniqueSpace()

AddrSpace * AddrSpaceManager::getUniqueSpace ( void  ) const
inline

Get the temporary register space for this processor.

Both the pcode translation process and the simplification process need access to a pool of temporary registers that can be used for moving data around without affecting the address spaces used to formally model the processor's RAM and registers. These temporary locations are all allocated from a dedicated address space, referred to as the unique space. (See UniqueSpace)

Returns
a pointer to the unique space

References uniqspace.

Referenced by ExecutablePcode::build(), and Sleigh::oneInstruction().

◆ insertResolver()

void AddrSpaceManager::insertResolver ( AddrSpace spc,
AddressResolver rsolv 
)
protected

Override the base resolver for a space.

Provide a new specialized resolver for a specific AddrSpace. The manager takes ownership of resolver.

Parameters
spcis the space to which the resolver is associated
rsolvis the new resolver object

References AddrSpace::getIndex(), and resolvelist.

Referenced by Architecture::initializeSegments().

◆ insertSpace()

void AddrSpaceManager::insertSpace ( AddrSpace spc)
protected

Add a new address space to the model.

This adds a previously instantiated address space (AddrSpace) to the model for this processor. It checks a set of indexing and naming conventions for the space and throws an exception if the conventions are violated. Should only be called during initialization.

Todo:
This really shouldn't be public. Need to move the allocation of iop, fspec, and join out of Architecture
Parameters
spcthe address space to insert

References baselist, constantspace, fspecspace, OverlaySpace::getBaseSpace(), AddrSpace::getIndex(), AddrSpace::getName(), AddrSpace::getType(), iopspace, IPTR_CONSTANT, IPTR_FSPEC, IPTR_INTERNAL, IPTR_IOP, IPTR_JOIN, IPTR_PROCESSOR, IPTR_SPACEBASE, AddrSpace::isOverlay(), joinspace, AddrSpace::overlaybase, AddrSpace::refcount, AddrSpace::setFlags(), stackspace, and uniqspace.

Referenced by Architecture::addSpacebase(), copySpaces(), Architecture::restoreFromSpec(), and restoreXmlSpaces().

◆ numSpaces()

int4 AddrSpaceManager::numSpaces ( void  ) const
inline

Get the number of address spaces for this processor.

This returns the total number of address spaces used by the processor, including all special spaces, like the constant space and the iop space.

Returns
the number of spaces

References baselist.

Referenced by Architecture::addSpacebase(), ActionNameVars::apply(), ActionDeadCode::apply(), ConditionalExecution::buildHeritageArray(), Heritage::buildInfoList(), Architecture::getSpaceBySpacebase(), Architecture::globalify(), Heritage::heritage(), Architecture::parseGlobal(), Architecture::restoreFromSpec(), SleighBase::saveXml(), ScopeInternal::ScopeInternal(), and Funcdata::spacebase().

◆ restoreXmlSpace()

AddrSpace * AddrSpaceManager::restoreXmlSpace ( const Element el,
const Translate trans 
)
protected

Add a space to the model based an on XML tag.

The initialization of address spaces is the same across all variants of the Translate object. This routine initializes a single address space from a parsed XML tag. It knows which class derived from AddrSpace to instantiate based on the tag name.

Parameters
elis the parsed XML tag
transis the translator object to be associated with the new space
Returns
a pointer to the initialized AddrSpace

References IPTR_PROCESSOR, and AddrSpace::restoreXml().

Referenced by restoreXmlSpaces().

◆ restoreXmlSpaces()

void AddrSpaceManager::restoreXmlSpaces ( const Element el,
const Translate trans 
)
protected

Restore address spaces in the model from an XML tag.

This routine initializes (almost) all the address spaces used for a particular processor by using a <spaces> tag, which contains subtags for the specific address spaces. This also instantiates the builtin constant space. It should probably also instantiate the iop, fspec, and join spaces, but this is currently done by the Architecture class.

Parameters
elis the parsed <spaces> tag
transis the processor translator to be associated with the spaces

References AddrSpace::getIndex(), getSpaceByName(), insertSpace(), restoreXmlSpace(), and setDefaultSpace().

Referenced by GhidraTranslate::restoreXml(), and SleighBase::restoreXml().

◆ setDeadcodeDelay()

void AddrSpaceManager::setDeadcodeDelay ( int4  spcnum,
int4  delaydelta 
)

Set the deadcodedelay for a specific space.

Set the number of passes for a specific AddrSpace before deadcode removal is allowed for that space.

Parameters
spcnumis the index of the AddrSpace to change
delaydeltais the number of rounds to the delay should be set to

References baselist.

Referenced by Architecture::parseDeadcodeDelay().

◆ setDefaultSpace()

void AddrSpaceManager::setDefaultSpace ( int4  index)
protected

Set the default address space.

Once all the address spaces have been initialized, this routine should be called once to establish the official default space for the processor, via its index. Should only be called during initialization.

Todo:
This really shouldn't be public
Parameters
indexis the index of the desired default space

References baselist, and defaultspace.

Referenced by copySpaces(), and restoreXmlSpaces().

◆ setReverseJustified()

void AddrSpaceManager::setReverseJustified ( AddrSpace spc)
protected

Set reverse justified property on this space.

For spaces with alignment restrictions, the address of a small variable must be justified within a larger aligned memory word, usually either to the left boundary for little endian encoding or to the right boundary for big endian encoding. Some compilers justify small variables to the opposite side of the one indicated by the endianness. Setting this property on a space causes the decompiler to use this justification

References AddrSpace::reverse_justification, and AddrSpace::setFlags().

Referenced by Architecture::addSpacebase().

◆ truncateSpace()

void AddrSpaceManager::truncateSpace ( const TruncationTag tag)

Mark a space as truncated from its original size.

Mark the named space as truncated from its original size

Parameters
tagis a description of the space and how it should be truncated

References TruncationTag::getName(), TruncationTag::getSize(), getSpaceByName(), and AddrSpace::truncateSpace().

Referenced by SleighArchitecture::modifySpaces(), and GhidraTranslate::restoreXml().


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