Skip to content

Ghidra is a software reverse engineering (SRE) framework

GP-7167 highPtrPossible in ActionConstantPtr

caheckmanf17a0b571910
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/address.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/address.cc
index 1d3136926f..add6bb31c1 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/address.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/address.cc
@@ -185,12 +185,21 @@ bool Address::isContiguous(int4 sz,const Address &loaddr,int4 losz) const
return false;
}
+/// If pointers are possible anywhere within the \b size byte region return \b true, \b false otherwise.
+/// \param size is the number bytes in the region
+/// \return \b true if pointers into the region are possible
+bool Address::highPtrPossible(int4 size) const
+
+{
+ return base->manage->highPtrPossible(*this, size);
+}
+
/// If \b this is (originally) a \e join address, reevaluate it in terms of its new
/// \e offset and \e size, changing the space and offset if necessary.
/// \param size is the new size in bytes of the underlying object
void Address::renormalize(int4 size) {
if (base->getType() == IPTR_JOIN)
- base->getManager()->renormalizeJoinAddress(*this,size);
+ base->manage->renormalizeJoinAddress(*this,size);
}
/// This is usually used to decode an address from an \b \<addr\>
@@ -457,15 +466,15 @@ void RangeList::merge(const RangeList &op2)
while(iter1 != iter2) {
const Range &range( *iter1 );
++iter1;
- insertRange(range.spc, range.first, range.last);
+ insertRange(range);
}
}
/// Make sure indicated range of addresses is \e contained in \b this RangeList
/// \param addr is the first Address in the target range
/// \param size is the number of bytes in the target range
-/// \return \b true is the range is fully contained by this RangeList
-bool RangeList::inRange(const Address &addr,int4 size) const
+/// \return \b true if the range is fully contained by this RangeList
+bool RangeList::inRange(const Address &addr,uintb size) const
{
set<Range>::const_iterator iter;
@@ -489,6 +498,24 @@ bool RangeList::inRange(const Address &addr,int4 size) const
return false;
}
+/// \param rng is the target range
+/// \return \b true if the range is fully contained by this RangeList
+bool RangeList::inRange(const Range &rng) const
+
+{
+ set<Range>::const_iterator iter;
+
+ if (tree.empty()) return false;
+
+ // iter = first range with its first > rng.first
+ iter = tree.upper_bound(rng);
+ if (iter == tree.begin()) return false;
+ // Set iter to last range with range.first <= rng.first
+ --iter;
+ if ((*iter).spc != rng.getSpace()) return false;
+ return ((*iter).last >= rng.last);
+}
+
/// If \b this RangeList contains the specific address (spaceid,offset), return it
/// \return the containing Range or NULL
const Range *RangeList::getRange(AddrSpace *spaceid,uintb offset) const
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/address.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/address.hh
index 8836e913c1..f2ef7a9ae9 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/address.hh
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/address.hh
@@ -94,6 +94,7 @@ public:
int4 overlapJoin(int4 skip,const Address &op,int4 size) const; ///< Determine how \b this falls in a possible \e join space address range
bool isContiguous(int4 sz,const Address &loaddr,int4 losz) const; ///< Does \e this form a contiguous range with \e loaddr
bool isConstant(void) const; ///< Is this a \e constant \e value
+ bool highPtrPossible(int4 size) const; ///< Are pointers possible to \b this address
void renormalize(int4 size); ///< Make sure there is a backing JoinRecord if \b this is in the \e join space
bool isJoin(void) const; ///< Is this a \e join \e value
void encode(Encoder &encoder) const; ///< Encode \b this to a stream
@@ -246,9 +247,12 @@ public:
const Range *getRange(AddrSpace *spaceid,uintb offset) const; ///< Get Range containing the given byte
const Range *getNearestRange(AddrSpace *spaceid,uintb offset) const; ///< Get the nearest Range to the given byte
void insertRange(AddrSpace *spc,uintb first,uintb last); ///< Insert a range of addresses
+ void insertRange(const Range &rng) { insertRange(rng.getSpace(),rng.getFirst(),rng.getLast()); } ///< Insert a range
void removeRange(AddrSpace *spc,uintb first,uintb last); ///< Remove a range of addresses
+ void removeRange(const Range &rng) { removeRange(rng.getSpace(),rng.getFirst(),rng.getLast()); } ///< Remove a range
void merge(const RangeList &op2); ///< Merge another RangeList into \b this
- bool inRange(const Address &addr,int4 size) const; ///< Check containment an address range
+ bool inRange(const Address &addr,uintb size) const; ///< Check containment an address range
+ bool inRange(const Range &rng) const; ///< Check containment of given range
uintb longestFit(const Address &addr,uintb maxsize) const; ///< Find size of biggest Range containing given address
void printBounds(ostream &s) const; ///< Print a description of \b this RangeList to stream
void encode(Encoder &encoder) const; ///< Encode \b this RangeList to a stream
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.cc
index 385cd2523d..ac7d261054 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.cc
@@ -581,16 +581,6 @@ void Architecture::addSpacebase(AddrSpace *basespace,const string &nm,const Varn
addSpacebasePointer(spc,ptrdata,truncSize,stackGrowth);
}
-/// This routine is used by the initialization process to add
-/// address ranges to which there is never an (indirect) pointer
-/// Should only be called during initialization
-/// \param rng is the new range with no aliases to be added
-void Architecture::addNoHighPtr(const Range &rng)
-
-{
- nohighptr.insertRange(rng.getSpace(),rng.getFirst(),rng.getLast());
-}
-
/// This builds the \e universal Action for function transformation
/// and instantiates the "decompile" root Action
/// \param store may hold configuration information
@@ -688,7 +678,7 @@ void Architecture::cacheAddrSpaceProperties(void)
AddrSpace *spc = copyList[i];
if (spc == lastSpace) continue;
lastSpace = spc;
- if (spc->getDelay() == 0) continue; // Don't put in a register space
+ if (spc->noHighPtrPossible()) continue; // Don't put in a register space
if (spc->getType() == IPTR_SPACEBASE) continue;
if (spc->isOtherSpace()) continue;
if (spc->isOverlay()) continue;
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.hh
index 3c8d0ca61e..a27f842620 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.hh
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.hh
@@ -199,7 +199,6 @@ public:
const Translate *translate; ///< Translation method for this binary
LoadImage *loader; ///< Method for loading portions of binary
PcodeInjectLibrary *pcodeinjectlib; ///< Pcode injection manager
- RangeList nohighptr; ///< Ranges for which high-level pointers are not possible
CommentDatabase *commentdb; ///< Comments for this architecture
StringManager *stringManager; ///< Manager of decoded strings
ConstantPool *cpool; ///< Deferred constant values
@@ -225,7 +224,6 @@ public:
ProtoModel *getModel(const string &nm) const; ///< Get a specific PrototypeModel
bool hasModel(const string &nm) const; ///< Does this Architecture have a specific PrototypeModel
ProtoModel *createUnknownModel(const string &modelName); ///< Create a model for an unrecognized name
- bool highPtrPossible(const Address &loc,int4 size) const; ///< Are pointers possible to the given location?
AddrSpace *getSpaceBySpacebase(const Address &loc,int4 size) const; ///< Get space associated with a \e spacebase register
const LanedRegister *getLanedRegister(const Address &loc,int4 size) const; ///< Get LanedRegister associated with storage
int4 getMinimumLanedRegisterSize(void) const; ///< Get the minimum size of a laned register in bytes
@@ -260,7 +258,6 @@ public:
protected:
void addSpacebase(AddrSpace *basespace,const string &nm,const VarnodeData &ptrdata,
int4 truncSize,bool isreversejustified,bool stackGrowth,bool isFormal);
- void addNoHighPtr(const Range &rng); ///< Add a new region where pointers do not exist
// Factory routines for building this architecture
virtual Scope *buildDatabase(DocumentStorage &store); ///< Build the database and global scope for this executable
@@ -399,18 +396,5 @@ public:
virtual Address resolve(uintb val,int4 sz,const Address &point,uintb &fullEncoding);
};
-/// The Translate object keeps track of address ranges for which
-/// it is effectively impossible to have a pointer into. This is
-/// used for pointer aliasing calculations. This routine returns
-/// \b true if it is \e possible to have pointers into the indicated
-/// range.
-/// \param loc is the starting address of the range
-/// \param size is the size of the range in bytes
-/// \return \b true if pointers are possible
-inline bool Architecture::highPtrPossible(const Address &loc,int4 size) const {
- if (loc.getSpace()->getType() == IPTR_INTERNAL) return false;
- return !nohighptr.inRange(loc,size);
-}
-
} // End namespace ghidra
#endif
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.cc
index 3dd322cb17..ad746815f8 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.cc
@@ -1150,6 +1150,7 @@ MapEntry *ActionConstantPtr::isPointer(AddrSpace *spc,Varnode *vn,PcodeOp *op,in
}
if (rampoint.isInvalid()) return (MapEntry *)0;
+ if (!rampoint.highPtrPossible(1)) return (MapEntry *)0;
// Since we are looking for a global address
// Assume it is address tied and use empty usepoint
MapEntry *entry = data.getScopeLocal()->getParent()->queryContainer(rampoint,1,Address());
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/database_ghidra.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/database_ghidra.cc
index 46cc03cc5b..b067d7ca5c 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/database_ghidra.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/database_ghidra.cc
@@ -85,7 +85,7 @@ void ScopeGhidra::decodeHole(Decoder &decoder) const
else if (attribId==ATTRIB_VOLATILE && decoder.readBool())
flags |= Varnode::volatil;
}
- holes.insertRange(range.getSpace(),range.getFirst(),range.getLast());
+ holes.insertRange(range);
decoder.closeElement(elemId);
if (flags != 0) {
ghidra->symboltab->setPropertyRange(flags,range);
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc
index ddf488d7d8..5dcf1dea27 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.cc
@@ -94,11 +94,9 @@ void ParamEntry::resolveFirst(list<ParamEntry> &curList)
void ParamEntry::resolveJoin(list<ParamEntry> &curList)
{
- if (spaceid->getType() != IPTR_JOIN) {
- joinrec = (JoinRecord *)0;
+ joinrec = spaceid->findJoin(addressbase);
+ if (joinrec == (JoinRecord *)0)
return;
- }
- joinrec = spaceid->getManager()->findJoin(addressbase);
groupSet.clear();
for(int4 i=0;i<joinrec->numPieces();++i) {
const ParamEntry *entry = findEntryByStorage(curList, joinrec->getPiece(i));
@@ -430,11 +428,12 @@ int4 ParamEntry::getSlot(const Address &addr,int4 skip) const
/// \param slotnum is a reference to used slots (which will be updated)
/// \param sz is the size of the parameter to allocated
/// \param typeAlign is the required byte alignment for the parameter
+/// \param m is the space manager
/// \return the address of the new parameter (or an invalid address)
-Address ParamEntry::getAddrBySlot(int4 &slotnum, int4 sz, int4 typeAlign) const
+Address ParamEntry::getAddrBySlot(int4 &slotnum, int4 sz, int4 typeAlign,const AddrSpaceManager *m) const
{
- return getAddrBySlot(slotnum, sz, typeAlign, !isLeftJustified());
+ return getAddrBySlot(slotnum, sz, typeAlign, !isLeftJustified(),m);
}
/// \brief Calculate the storage address assigned when allocating a parameter of a given size
@@ -446,8 +445,9 @@ Address ParamEntry::getAddrBySlot(int4 &slotnum, int4 sz, int4 typeAlign) const
/// \param sz is the size of the parameter to allocated
/// \param typeAlign is the required byte alignment for the parameter
/// \param justifyRight is true if initial bytes are padding for odd data-type sizes
+/// \param m is the space manager
/// \return the address of the new parameter (or an invalid address)
-Address ParamEntry::getAddrBySlot(int4 &slotnum,int4 sz,int4 typeAlign, bool justifyRight) const
+Address ParamEntry::getAddrBySlot(int4 &slotnum,int4 sz,int4 typeAlign, bool justifyRight,const AddrSpaceManager *m) const
{
Address res; // Start with an invalid result
@@ -459,8 +459,7 @@ Address ParamEntry::getAddrBySlot(int4 &slotnum,int4 sz,int4 typeAlign, bool jus
res = Address(spaceid,addressbase); // Get base address of the slot
spaceused = size;
if (((flags & smallsize_floatext)!=0)&&(sz != size)) { // Do we have an implied floating-point extension
- AddrSpaceManager *manager = spaceid->getManager();
- res = manager->constructFloatExtensionAddress(res,size,sz);
+ res = m->constructFloatExtensionAddress(res,size,sz);
return res;
}
}
@@ -604,6 +603,7 @@ ParamListStandard::ParamListStandard(const ParamListStandard &op2)
thisbeforeret = op2.thisbeforeret;
autoKilledByCall = op2.autoKilledByCall;
resourceStart = op2.resourceStart;
+ glb = op2.glb;
for(list<ModelRule>::const_iterator iter=op2.modelRules.begin();iter!=op2.modelRules.end();++iter) {
modelRules.emplace_back(*iter,&op2);
}
@@ -745,7 +745,7 @@ uint4 ParamListStandard::assignAddressFallback(type_class resource,Datatype *tp,
continue; // Wrong type
}
- param.addr = curEntry.getAddrBySlot(status[grp],tp->getAlignSize(),tp->getAlignment());
+ param.addr = curEntry.getAddrBySlot(status[grp],tp->getAlignSize(),tp->getAlignment(),glb);
if (param.addr.isInvalid()) continue; // If -tp- doesn't fit an invalid address is returned
if (curEntry.isExclusion()) {
const vector<int4> &groupSet(curEntry.getAllGroups());
@@ -892,7 +892,7 @@ void ParamListStandard::buildTrialMap(ParamActive *active) const
continue;
int4 sz = curentry->isExclusion() ? curentry->getSize() : curentry->getAlign();
int4 nextslot = 0;
- Address addr = curentry->getAddrBySlot(nextslot,sz,1);
+ Address addr = curentry->getAddrBySlot(nextslot,sz,1,glb);
int4 trialpos = active->getNumTrials();
active->registerTrial(addr,sz);
ParamTrial &paramtrial(active->getTrial(trialpos));
@@ -923,7 +923,7 @@ void ParamListStandard::buildTrialMap(ParamActive *active) const
for(int4 j=0;j<slotlist.size();++j) {
if (slotlist[j] == 0) {
int4 nextslot = j; // Make copy of j, so that getAddrBySlot can change it
- Address addr = curentry->getAddrBySlot(nextslot,curentry->getAlign(),1);
+ Address addr = curentry->getAddrBySlot(nextslot,curentry->getAlign(),1,glb);
int4 trialpos = active->getNumTrials();
active->registerTrial(addr,curentry->getAlign());
ParamTrial &paramtrial(active->getTrial(trialpos));
@@ -1451,6 +1451,7 @@ void ParamListStandard::getRangeList(AddrSpace *spc,RangeList &res) const
void ParamListStandard::decode(Decoder &decoder,vector<EffectRecord> &effectlist,bool normalstack)
{
+ glb = decoder.getAddrSpaceManager();
numgroup = 0;
spacebase = (AddrSpace *)0;
int4 pointermax = 0;
@@ -2633,7 +2634,7 @@ void ProtoModel::decode(Decoder &decoder)
while(decoder.peekElement() != 0) {
Range range;
range.decode(decoder);
- localrange.insertRange(range.getSpace(),range.getFirst(),range.getLast());
+ localrange.insertRange(range);
}
decoder.closeElement(subId);
}
@@ -2643,7 +2644,7 @@ void ProtoModel::decode(Decoder &decoder)
while(decoder.peekElement() != 0) {
Range range;
range.decode(decoder);
- paramrange.insertRange(range.getSpace(),range.getFirst(),range.getLast());
+ paramrange.insertRange(range);
}
decoder.closeElement(subId);
}
@@ -2853,9 +2854,9 @@ void ProtoModelMerged::foldIn(ProtoModel *model)
// Take the union of the localrange and paramrange
set<Range>::const_iterator iter;
for(iter=model->localrange.begin();iter!=model->localrange.end();++iter)
- localrange.insertRange((*iter).getSpace(),(*iter).getFirst(),(*iter).getLast());
+ localrange.insertRange(*iter);
for(iter=model->paramrange.begin();iter!=model->paramrange.end();++iter)
- paramrange.insertRange((*iter).getSpace(),(*iter).getFirst(),(*iter).getLast());
+ paramrange.insertRange(*iter);
}
}
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.hh
index 922c1a799e..725b4d5091 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.hh
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/fspec.hh
@@ -146,8 +146,8 @@ public:
int4 getSlot(const Address &addr,int4 skip) const;
AddrSpace *getSpace(void) const { return spaceid; } ///< Get the address space containing \b this entry
uintb getBase(void) const { return addressbase; } ///< Get the starting offset of \b this entry
- Address getAddrBySlot(int4 &slot, int4 sz, int4 typeAlign, bool justifyRight) const;
- Address getAddrBySlot(int4 &slot,int4 sz,int4 typeAlign) const;
+ Address getAddrBySlot(int4 &slot, int4 sz, int4 typeAlign, bool justifyRight,const AddrSpaceManager *m) const;
+ Address getAddrBySlot(int4 &slot,int4 sz,int4 typeAlign,const AddrSpaceManager *m) const;
void decode(Decoder &decoder,bool normalstack,bool grouped,list<ParamEntry> &curList);
bool isParamCheckHigh(void) const { return ((flags & extracheck_high)!=0); } ///< Return \b true if there is a high overlap
bool isParamCheckLow(void) const { return ((flags & extracheck_low)!=0); } ///< Return \b true if there is a low overlap
@@ -597,6 +597,7 @@ protected:
vector<ParamEntryResolver *> resolverMap; ///< Map from space id to resolver
list<ModelRule> modelRules; ///< Rules to apply when assigning addresses
AddrSpace *spacebase; ///< Address space containing relative offset parameters
+ const AddrSpaceManager *glb; ///< Owning manager
const ParamEntry *findEntry(const Address &loc,int4 size,bool just) const; ///< Given storage location find matching ParamEntry
const ParamEntry *selectUnreferenceEntry(int4 grp,type_class prefType) const; ///< Select entry to fill an unreferenced param
void buildTrialMap(ParamActive *active) const; ///< Build map from parameter trials to model ParamEntrys
@@ -618,6 +619,7 @@ public:
ParamListStandard(const ParamListStandard &op2); ///< Copy constructor
virtual ~ParamListStandard(void);
const list<ParamEntry> &getEntry(void) const { return entry; } ///< Get the list of parameter entries
+ const AddrSpaceManager *getManager(void) const { return glb; } ///< Get the owner
bool isBigEndian(void) const { return entry.front().getSpace()->isBigEndian(); } ///< Return \b true if resources are big endian
void extractTiles(vector<const ParamEntry *> &tiles,type_class type) const; ///< Get registers of given storage class
const ParamEntry *getStackEntry(void) const; ///< Get the stack entry
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/heritage.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/heritage.cc
index 8b0d8b3326..1644c014f5 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/heritage.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/heritage.cc
@@ -1192,7 +1192,7 @@ void Heritage::guard(const Address &addr,int4 size,bool addIndirects,
fd->getScopeLocal()->queryProperties(addr,size,Address(),fl);
guardCalls(fl,addr,size,write);
guardReturns(fl,addr,size,write);
- if (fd->getArch()->highPtrPossible(addr,size)) {
+ if (addr.highPtrPossible(size)) {
guardStores(addr,size,write);
guardLoads(fl,addr,size,write);
}
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/modelrules.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/modelrules.cc
index 3f4bb8ef35..612f1db483 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/modelrules.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/modelrules.cc
@@ -723,7 +723,7 @@ uint4 GotoStack::assignAddress(Datatype *dt,const PrototypePieces &proto,int4 po
{
int4 grp = stackEntry->getGroup();
res.type = dt;
- res.addr = stackEntry->getAddrBySlot(status[grp],dt->getSize(),dt->getAlignment());
+ res.addr = stackEntry->getAddrBySlot(status[grp],dt->getSize(),dt->getAlignment(),resource->getManager());
res.flags = 0;
return success;
}
@@ -858,7 +858,7 @@ uint4 MultiSlotAssign::assignAddress(Datatype *dt,const PrototypePieces &proto,i
if (tmpStatus[entry->getGroup()] != 0)
continue; // Already consumed
int4 trialSize = entry->getSize();
- Address addr = entry->getAddrBySlot(tmpStatus[entry->getGroup()], trialSize,align);
+ Address addr = entry->getAddrBySlot(tmpStatus[entry->getGroup()], trialSize,align,resource->getManager());
tmpStatus[entry->getGroup()] = -1; // Consume the register
pieces.push_back(VarnodeData());
pieces.back().space = addr.getSpace();
@@ -871,7 +871,8 @@ uint4 MultiSlotAssign::assignAddress(Datatype *dt,const PrototypePieces &proto,i
if (!consumeFromStack)
return fail;
int4 grp = stackEntry->getGroup();
- Address addr = stackEntry->getAddrBySlot(tmpStatus[grp],sizeLeft,align,justifyRight); // Consume all the space we need
+ // Consume all the space we need
+ Address addr = stackEntry->getAddrBySlot(tmpStatus[grp],sizeLeft,align,justifyRight,resource->getManager());
if (addr.isInvalid())
return fail;
pieces.push_back(VarnodeData());
@@ -1209,7 +1210,7 @@ uint4 MultiSlotDualAssign::assignAddress(Datatype *dt,const PrototypePieces &pro
entry = altTiles[iterAlt];
}
int4 trialSize = entry->getSize();
- Address addr = entry->getAddrBySlot(tmpStatus[entry->getGroup()], trialSize,1);
+ Address addr = entry->getAddrBySlot(tmpStatus[entry->getGroup()], trialSize,1,resource->getManager());
tmpStatus[entry->getGroup()] = -1; // Consume the register
pieces.push_back(VarnodeData());
pieces.back().space = addr.getSpace();
@@ -1221,7 +1222,8 @@ uint4 MultiSlotDualAssign::assignAddress(Datatype *dt,const PrototypePieces &pro
if (!consumeFromStack)
return fail;
int4 grp = stackEntry->getGroup();
- Address addr = stackEntry->getAddrBySlot(tmpStatus[grp],sizeLeft,align,justifyRight); // Consume all the space we need
+ // Consume all the space we need
+ Address addr = stackEntry->getAddrBySlot(tmpStatus[grp],sizeLeft,align,justifyRight,resource->getManager());
if (addr.isInvalid())
return fail;
pieces.push_back(VarnodeData());
@@ -1567,7 +1569,7 @@ uint4 ExtraStack::assignAddress(Datatype *dt,const PrototypePieces &proto,int4 p
}
// We assign the stack address (but ignore the actual address) updating the status for the stack,
// which consumes the stack resources.
- stackEntry->getAddrBySlot(status[grp],dt->getSize(),dt->getAlignment());
+ stackEntry->getAddrBySlot(status[grp],dt->getSize(),dt->getAlignment(),resource->getManager());
return success;
}
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/space.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/space.cc
index dbaa2e775f..6a8cc94d63 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/space.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/space.cc
@@ -78,6 +78,7 @@ AddrSpace::AddrSpace(AddrSpaceManager *m,const Translate *t,spacetype tp,const s
flags |= (heritaged | does_deadcode); // Always on unless explicitly turned off in derived constructor
calcScaleMask();
+ flags |= (delay == 0) ? addressable_none : addressable_all;
}
/// This is a partial constructor, for initializing a space
@@ -197,6 +198,18 @@ void AddrSpace::printOffset(ostream &s,uintb offset) const
s << "0x" << hex << offset;
}
+/// If \b this is not the \e join space, null is returned, otherwise look up any record
+/// associated with the given offset.
+/// \param offset is the given offset
+/// \return the record or null
+JoinRecord *AddrSpace::findJoin(uintb offset) const
+
+{
+ if (type != IPTR_JOIN)
+ return (JoinRecord *)0;
+ return manage->findJoin(offset);
+}
+
/// This is a printing method for the debugging routines. It
/// prints taking into account the \e wordsize, adding a
/// "+n" if the offset is not on-cut with wordsize. It also
@@ -456,7 +469,7 @@ int4 JoinSpace::overlapJoin(uintb offset,int4 size,AddrSpace *pointSpace,uintb p
{
if (this == pointSpace) {
// If the point is in the join space, translate the point into the piece address space
- JoinRecord *pieceRecord = getManager()->findJoin(pointOffset);
+ JoinRecord *pieceRecord = manage->findJoin(pointOffset);
int4 pos;
Address addr = pieceRecord->getEquivalentAddress(pointOffset + pointSkip, pos);
pointSpace = addr.getSpace();
@@ -467,7 +480,7 @@ int4 JoinSpace::overlapJoin(uintb offset,int4 size,AddrSpace *pointSpace,uintb p
return -1;
pointOffset = pointSpace->wrapOffset(pointOffset + pointSkip);
}
- JoinRecord *joinRecord = getManager()->findJoin(offset);
+ JoinRecord *joinRecord = manage->findJoin(offset);
// Set up so we traverse pieces in data order
int4 startPiece,endPiece,dir;
if (isBigEndian()) {
@@ -502,7 +515,7 @@ int4 JoinSpace::overlapJoin(uintb offset,int4 size,AddrSpace *pointSpace,uintb p
void JoinSpace::encodeAttributes(Encoder &encoder,uintb offset) const
{
- JoinRecord *rec = getManager()->findJoin(offset); // Record must already exist
+ JoinRecord *rec = manage->findJoin(offset); // Record must already exist
encoder.writeSpace(ATTRIB_SPACE, this);
int4 num = rec->numPieces();
if (num > MAX_PIECES)
@@ -572,7 +585,7 @@ uintb JoinSpace::decodeAttributes(Decoder &decoder,uint4 &size) const
if (szpos==string::npos)
throw LowlevelError("join address piece attribute is malformed");
string spcname = attrVal.substr(0,offpos);
- vdat.space = getManager()->getSpaceByName(spcname);
+ vdat.space = manage->getSpaceByName(spcname);
istringstream s1(attrVal.substr(offpos+1,szpos));
s1.unsetf(ios::dec | ios::hex | ios::oct);
s1 >> vdat.offset;
@@ -582,7 +595,7 @@ uintb JoinSpace::decodeAttributes(Decoder &decoder,uint4 &size) const
}
sizesum += vdat.size;
}
- JoinRecord *rec = getManager()->findAddJoin(pieces,logicalsize);
+ JoinRecord *rec = manage->findAddJoin(pieces,logicalsize);
size = rec->getUnified().size;
return rec->getUnified().offset;
}
@@ -590,7 +603,7 @@ uintb JoinSpace::decodeAttributes(Decoder &decoder,uint4 &size) const
void JoinSpace::printRaw(ostream &s,uintb offset) const
{
- JoinRecord *rec = getManager()->findJoin(offset);
+ JoinRecord *rec = manage->findJoin(offset);
int4 szsum = 0;
int4 num = rec->numPieces();
s << '{';
@@ -627,7 +640,7 @@ uintb JoinSpace::read(const string &s,int4 &size) const
}
catch(LowlevelError &err) { // Name doesn't exist
char tryShortcut = token[0];
- AddrSpace *spc = getManager()->getSpaceByShortcut(tryShortcut);
+ AddrSpace *spc = manage->getSpaceByShortcut(tryShortcut);
if (spc == (AddrSpace *)0)
throw LowlevelError("Could not parse join string");
@@ -638,7 +651,7 @@ uintb JoinSpace::read(const string &s,int4 &size) const
}
szsum += pieces.back().size;
}
- JoinRecord *rec = getManager()->findAddJoin(pieces,0);
+ JoinRecord *rec = manage->findAddJoin(pieces,0);
size = szsum;
return rec->getUnified().offset;
}
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/space.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/space.hh
index ff49ee951c..75b24463e5 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/space.hh
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/space.hh
@@ -39,8 +39,10 @@ enum spacetype {
class AddrSpace;
class AddrSpaceManager;
+class Address;
struct VarnodeData;
class Translate;
+class JoinRecord;
extern AttributeId ATTRIB_BASE; ///< Marshaling attribute "base"
extern AttributeId ATTRIB_DEADCODEDELAY; ///< Marshaling attribute "deadcodedelay"
@@ -81,6 +83,7 @@ extern AttributeId ATTRIB_PIECE; ///< Marshaling attribute "piece"
///
class AddrSpace {
friend class AddrSpaceManager; // Space container
+ friend class Address;
public:
enum {
big_endian = 1, ///< Space is big endian if set, little endian otherwise
@@ -95,19 +98,21 @@ public:
hasphysical = 0x200, ///< Has physical memory associated with it
is_otherspace = 0x400, ///< Quick check for the OtherSpace derived class
has_nearpointers = 0x800, ///< Does there exist near pointers into this space
- allows_wrapped_range = 0x1000 ///< A memory range for \b this space can wrap from high addresses to low
+ allows_wrapped_range = 0x1000, ///< A memory range for \b this space can wrap from high addresses to low
+ addressable_all = 0x2000, ///< Pointers can address the entire space
+ addressable_none = 0x4000 ///< Pointers do not exist into \b this space
};
private:
- spacetype type; ///< Type of space (PROCESSOR, CONSTANT, INTERNAL, ...)
- AddrSpaceManager *manage; ///< Manager for processor using this space
const Translate *trans; ///< Processor translator (for register names etc) for this space
+ spacetype type; ///< Type of space (PROCESSOR, CONSTANT, INTERNAL, ...)
int4 refcount; ///< Number of managers using this space
uint4 flags; ///< Attributes of the space
+ char shortcut; ///< Shortcut character for printing
uintb highest; ///< Highest (byte) offset into this space
uintb pointerLowerBound; ///< Offset below which we don't search for pointers
uintb pointerUpperBound; ///< Offset above which we don't search for pointers
- char shortcut; ///< Shortcut character for printing
protected:
+ AddrSpaceManager *manage; ///< Manager for processor using this space
string name; ///< Name of this space
uint4 addressSize; ///< Size of an address into this space in bytes
uint4 wordsize; ///< Size of unit being addressed (1=byte)
@@ -126,7 +131,6 @@ public:
AddrSpace(AddrSpaceManager *m,const Translate *t,spacetype tp); ///< For use with decode
virtual ~AddrSpace(void) {} ///< The address space destructor
const string &getName(void) const; ///< Get the name
- AddrSpaceManager *getManager(void) const; ///< Get the space manager
const Translate *getTrans(void) const; ///< Get the processor translator
spacetype getType(void) const; ///< Get the type of space
int4 getDelay(void) const; ///< Get number of heritage passes being delayed
@@ -150,9 +154,11 @@ public:
bool isOverlayBase(void) const; ///< Return \b true if other spaces overlay this space
bool isOtherSpace(void) const; ///< Return \b true if \b this is the \e other address space
bool isTruncated(void) const; ///< Return \b true if this space is truncated from its original size
+ bool noHighPtrPossible(void) const; ///< Return \b true if there can be pointers into \b this space
bool hasNearPointers(void) const; ///< Return \b true if \e near (truncated) pointers into \b this space are possible
bool allowsWrappedRange(void) const; ///< Return \b true if memory range can span high to low addresses in \b this space
void printOffset(ostream &s,uintb offset) const; ///< Write an address offset to a stream
+ JoinRecord *findJoin(uintb offset) const; ///< Find \e join record for offset in \b this space
virtual int4 numSpacebase(void) const; ///< Number of base registers associated with this space
virtual const VarnodeData &getSpacebase(int4 i) const; ///< Get a base register that creates this virtual space
@@ -280,13 +286,6 @@ inline const string &AddrSpace::getName(void) const {
return name;
}
-/// Every address space is associated with a manager of (all possible) spaces.
-/// This method recovers the address space manager object.
-/// \return a pointer to the address space manager
-inline AddrSpaceManager *AddrSpace::getManager(void) const {
- return manage;
-}
-
/// Every address space is associated with a processor which may have additional objects
/// like registers etc. associated with it. This method returns a pointer to that processor
/// translator
@@ -465,6 +464,10 @@ inline bool AddrSpace::isTruncated(void) const {
return ((flags&truncated)!=0);
}
+inline bool AddrSpace::noHighPtrPossible(void) const {
+ return ((flags & addressable_none)!=0);
+}
+
inline bool AddrSpace::hasNearPointers(void) const {
return ((flags&has_nearpointers)!=0);
}
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/stringmanage.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/stringmanage.cc
index f042000ba2..142773975d 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/stringmanage.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/stringmanage.cc
@@ -190,7 +190,7 @@ uint8 StringManager::registerInternalStringData(const Address &addr,const uint1
if (numChars < 0)
return 0; // Not a legal encoding
uint8 hash = calcInternalHash(addr, buf, size);
- Address constAddr = addr.getSpace()->getManager()->getConstant(hash);
+ Address constAddr = addr.getSpace()->getTrans()->getConstant(hash);
StringData &stringData( stringMap[constAddr] );
stringData.byteData.clear();
stringData.isTruncated = false;
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/translate.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/translate.cc
index 2bc5425031..12c6a245d1 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/translate.cc
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/translate.cc
@@ -455,6 +455,29 @@ void AddrSpaceManager::addSpacebasePointer(SpacebaseSpace *basespace,const Varno
basespace->setBaseRegister(ptrdata,truncSize,stackGrowth);
}
+/// This routine is used by the initialization process to add
+/// address ranges to which there is never an (indirect) pointer
+/// Should only be called during initialization
+/// \param rng is the new range with no aliases to be added
+void AddrSpaceManager::addNoHighPtr(const Range &rng)
+
+{
+ AddrSpace *spc = rng.getSpace();
+ if (spc->manage != this) { // Make sure the manager matches the range
+ spc->manage->addNoHighPtr(rng);
+ return;
+ }
+ if ((spc->flags & AddrSpace::addressable_none)!=0)
+ return; // Whole space already unaddressable
+ if ((spc->flags & AddrSpace::addressable_all) != 0)
+ spc->flags &= ~(uint4)AddrSpace::addressable_all;
+ nohighptr.insertRange(spc,rng.getFirst(),rng.getLast());
+ Range whole(spc,0,spc->getHighest());
+ if (nohighptr.inRange(whole)) {
+ spc->flags |= AddrSpace::addressable_none;
+ }
+}
+
/// Provide a new specialized resolver for a specific AddrSpace. The manager takes ownership of resolver.
/// \param spc is the space to which the resolver is associated
/// \param rsolv is the new resolver object
@@ -660,7 +683,7 @@ AddrSpace *AddrSpaceManager::getNextSpaceInOrder(AddrSpace *spc) const
/// \param pieces if the list memory locations to be joined
/// \param logicalsize of a \e single \e piece join, or zero
/// \return a pointer to the JoinRecord
-JoinRecord *AddrSpaceManager::findAddJoin(const vector<VarnodeData> &pieces,uint4 logicalsize)
+JoinRecord *AddrSpaceManager::findAddJoin(const vector<VarnodeData> &pieces,uint4 logicalsize) const
{ // Find a pre-existing split record, or create a new one corresponding to the input -pieces-
// If -logicalsize- is 0, calculate logical size as sum of pieces
@@ -782,7 +805,7 @@ void AddrSpaceManager::truncateSpace(const TruncationTag &tag)
/// \param realsize is the size of the real floating-point register
/// \param logicalsize is the size (lower precision) size of the logical value
Address AddrSpaceManager::constructFloatExtensionAddress(const Address &realaddr,int4 realsize,
- int4 logicalsize)
+ int4 logicalsize) const
{
if (logicalsize == realsize)
return realaddr;
@@ -808,7 +831,7 @@ Address AddrSpaceManager::constructFloatExtensionAddress(const Address &realaddr
/// \return an address representing the start of the joined range
Address AddrSpaceManager::constructJoinAddress(const Translate *translate,
const Address &hiaddr,int4 hisz,
- const Address &loaddr,int4 losz)
+ const Address &loaddr,int4 losz) const
{
spacetype hitp = hiaddr.getSpace()->getType();
spacetype lotp = loaddr.getSpace()->getType();
@@ -856,7 +879,7 @@ Address AddrSpaceManager::constructJoinAddress(const Translate *translate,
/// \param addr is the initial address in the range
/// \param size is the number of bytes in the range
/// \return the address representing the wrapped range
-Address AddrSpaceManager::constructWrappingAddress(const Address &addr,int4 size)
+Address AddrSpaceManager::constructWrappingAddress(const Address &addr,int4 size) const
{
AddrSpace *spc = addr.getSpace();
@@ -891,7 +914,7 @@ Address AddrSpaceManager::constructWrappingAddress(const Address &addr,int4 size
/// either to the offset corresponding to the new JoinRecord or to a normal \e non-join Address.
/// \param addr is the given Address
/// \param size is the size of the range in bytes
-void AddrSpaceManager::renormalizeJoinAddress(Address &addr,int4 size)
+void AddrSpaceManager::renormalizeJoinAddress(Address &addr,int4 size) const
{
JoinRecord *joinRecord = findJoinInternal(addr.getOffset());
@@ -944,7 +967,7 @@ void AddrSpaceManager::renormalizeJoinAddress(Address &addr,int4 size)
/// \param join is the JoinRecord to strip
/// \param index is the index of the piece to strip, which must be at the front or back
/// \return the VarnodeData corresponding to the remaining piece(s)
-const VarnodeData &AddrSpaceManager::stripJoinPiece(JoinRecord *join,int4 index)
+const VarnodeData &AddrSpaceManager::stripJoinPiece(JoinRecord *join,int4 index) const
{
int4 start,end;
@@ -972,7 +995,7 @@ const VarnodeData &AddrSpaceManager::stripJoinPiece(JoinRecord *join,int4 index)
/// by ':' to separate it from the offset. If the name is not present, the default data space is assumed.
/// \param val is the string to parse
/// \return the parsed address
-Address AddrSpaceManager::parseAddressSimple(const string &val)
+Address AddrSpaceManager::parseAddressSimple(const string &val) const
{
string::size_type col = val.find(':');
diff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/translate.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/translate.hh
index 0048fb772f..09018f491e 100644
--- a/Ghidra/Features/Decompiler/src/decompile/cpp/translate.hh
+++ b/Ghidra/Features/Decompiler/src/decompile/cpp/translate.hh
@@ -230,9 +230,10 @@ class AddrSpaceManager {
AddrSpace *joinspace; ///< Space for unifying split variables
AddrSpace *stackspace; ///< Stack space associated with processor
AddrSpace *uniqspace; ///< Temporary space associated with processor
- uintb joinallocate; ///< Next offset to be allocated in join space
- set<JoinRecord *,JoinRecordCompare> splitset; ///< Different splits that have been defined in join space
- vector<JoinRecord *> splitlist; ///< JoinRecords indexed by join address
+ RangeList nohighptr; ///< Ranges for which high-level pointers are not possible
+ mutable uintb joinallocate; ///< Next offset to be allocated in join space
+ mutable set<JoinRecord *,JoinRecordCompare> splitset; ///< Different splits that have been defined in join space
+ mutable vector<JoinRecord *> splitlist; ///< JoinRecords indexed by join address
protected:
AddrSpace *decodeSpace(Decoder &decoder,const Translate *trans); ///< Add a space to the model based an on XML tag
void decodeSpaces(Decoder &decoder,const Translate *trans); ///< Restore address spaces in the model from a stream
@@ -244,6 +245,7 @@ protected:
void insertSpace(AddrSpace *spc); ///< Add a new address space to the model
void copySpaces(const AddrSpaceManager *op2); ///< Copy spaces from another manager
void addSpacebasePointer(SpacebaseSpace *basespace,const VarnodeData &ptrdata,int4 truncSize,bool stackGrowth); ///< Set the base register of a spacebase space
+ void addNoHighPtr(const Range &rng); ///< Add a new region where pointers do not exist
void insertResolver(AddrSpace *spc,AddressResolver *rsolv); ///< Override the base resolver for a space
void setInferPtrBounds(const Range &range); ///< Set the range of addresses that can be inferred as pointers
JoinRecord *findJoinInternal(uintb offset) const; ///< Find JoinRecord for \e offset in the join space
@@ -262,33 +264,35 @@ public:
AddrSpace *getDefaultDataSpace(void) const; ///< Get the default address space where data is stored
AddrSpace *getConstantSpace(void) const; ///< Get the constant space
Address getConstant(uintb val) const; ///< Get a constant encoded as an Address
+ bool highPtrPossible(const Address &loc,int4 size) const; ///< Are pointers possible to the given location?
Address createConstFromSpace(AddrSpace *spc) const; ///< Create a constant address encoding an address space
Address resolveConstant(AddrSpace *spc,uintb val,int4 sz,const Address &point,uintb &fullEncoding) const;
int4 numSpaces(void) const; ///< Get the number of address spaces for this processor
AddrSpace *getSpace(int4 i) const; ///< Get an address space via its index
AddrSpace *getNextSpaceInOrder(AddrSpace *spc) const; ///< Get the next \e contiguous address space
- JoinRecord *findAddJoin(const vector<VarnodeData> &pieces,uint4 logicalsize); ///< Get (or create) JoinRecord for \e pieces
+ JoinRecord *findAddJoin(const vector<VarnodeData> &pieces,uint4 logicalsize) const; ///< Get (or create) JoinRecord for \e pieces
JoinRecord *findJoin(uintb offset) const; ///< Find JoinRecord for \e offset in the join space
void setDeadcodeDelay(AddrSpace *spc,int4 delaydelta); ///< Set the deadcodedelay for a specific space
void truncateSpace(const TruncationTag &tag); ///< Mark a space as truncated from its original size
/// \brief Build a logically lower precision storage location for a bigger floating point register
- Address constructFloatExtensionAddress(const Address &realaddr,int4 realsize,int4 logicalsize);
+ Address constructFloatExtensionAddress(const Address &realaddr,int4 realsize,int4 logicalsize) const;
/// \brief Build a logical whole from register pairs
- Address constructJoinAddress(const Translate *translate,const Address &hiaddr,int4 hisz,const Address &loaddr,int4 losz);
+ Address constructJoinAddress(const Translate *translate,const Address &hiaddr,int4 hisz,
+ const Address &loaddr,int4 losz) const;
/// \brief Build a logical whole representing a range that \e wraps from a high address to a low address
- Address constructWrappingAddress(const Address &addr,int4 size);
+ Address constructWrappingAddress(const Address &addr,int4 size)const ;
/// \brief Make sure a possibly offset \e join address has a proper JoinRecord
- void renormalizeJoinAddress(Address &addr,int4 size);
+ void renormalizeJoinAddress(Address &addr,int4 size) const;
/// \brief Create an Address by stripping a piece from a JoinRecord
- const VarnodeData &stripJoinPiece(JoinRecord *join,int4 index);
+ const VarnodeData &stripJoinPiece(JoinRecord *join,int4 index) const;
/// \brief Parse a string with just an \e address \e space name and a hex offset
- Address parseAddressSimple(const string &val);
+ Address parseAddressSimple(const string &val) const;
};
/// \brief The interface to a translation engine for a processor.
@@ -539,6 +543,21 @@ inline Address AddrSpaceManager::getConstant(uintb val) const {
return Address(constantspace,val);
}
+/// The Translate object keeps track of address ranges for which
+/// it is effectively impossible to have a pointer into. This is
+/// used for pointer aliasing calculations. This routine returns
+/// \b true if it is \e possible to have pointers into the indicated
+/// range.
+/// \param loc is the starting address of the range
+/// \param size is the size of the range in bytes
+/// \return \b true if pointers are possible
+inline bool AddrSpaceManager::highPtrPossible(const Address &loc,int4 size) const {
+ uint4 fl = loc.getSpace()->flags & (AddrSpace::addressable_all | AddrSpace::addressable_none);
+ if (fl != 0)
+ return (fl == AddrSpace::addressable_all);
+ return !nohighptr.inRange(loc,size);
+}
+
/// This routine is used to encode a pointer to an address space
/// as a \e constant Address, for use in \b LOAD and \b STORE
/// operations. This is used internally and is slightly more
diff --git a/Ghidra/Processors/RISCV/data/languages/riscv32-fp.cspec b/Ghidra/Processors/RISCV/data/languages/riscv32-fp.cspec
index 927b8ea4b3..3ac91f50e7 100644
--- a/Ghidra/Processors/RISCV/data/languages/riscv32-fp.cspec
+++ b/Ghidra/Processors/RISCV/data/languages/riscv32-fp.cspec
@@ -26,6 +26,9 @@
<register name="gp"/>
<register name="tp"/>
</global>
+ <nohighptr>
+ <range space="csreg"/>
+ </nohighptr>
<returnaddress>
<register name="ra"/>
</returnaddress>
diff --git a/Ghidra/Processors/RISCV/data/languages/riscv64-fp.cspec b/Ghidra/Processors/RISCV/data/languages/riscv64-fp.cspec
index fd17e478a2..256937b478 100644
--- a/Ghidra/Processors/RISCV/data/languages/riscv64-fp.cspec
+++ b/Ghidra/Processors/RISCV/data/languages/riscv64-fp.cspec
@@ -26,6 +26,9 @@
<register name="gp"/>
<register name="tp"/>
</global>
+ <nohighptr>
+ <range space="csreg"/>
+ </nohighptr>
<returnaddress>
<register name="ra"/>
</returnaddress>