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.ccindex 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) constreturn 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 objectvoid 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) constreturn 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 NULLconst Range *RangeList::getRange(AddrSpace *spaceid,uintb offset) constdiff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/address.hh b/Ghidra/Features/Decompiler/src/decompile/cpp/address.hhindex 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 rangebool isContiguous(int4 sz,const Address &loaddr,int4 losz) const; ///< Does \e this form a contiguous range with \e loaddrbool isConstant(void) const; ///< Is this a \e constant \e value+ bool highPtrPossible(int4 size) const; ///< Are pointers possible to \b this addressvoid renormalize(int4 size); ///< Make sure there is a backing JoinRecord if \b this is in the \e join spacebool isJoin(void) const; ///< Is this a \e join \e valuevoid 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 byteconst Range *getNearestRange(AddrSpace *spaceid,uintb offset) const; ///< Get the nearest Range to the given bytevoid 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 rangevoid 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 rangevoid 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 rangeuintb longestFit(const Address &addr,uintb maxsize) const; ///< Find size of biggest Range containing given addressvoid printBounds(ostream &s) const; ///< Print a description of \b this RangeList to streamvoid encode(Encoder &encoder) const; ///< Encode \b this RangeList to a streamdiff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/architecture.ccindex 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 VarnaddSpacebasePointer(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 spaceif (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.hhindex 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 binaryLoadImage *loader; ///< Method for loading portions of binaryPcodeInjectLibrary *pcodeinjectlib; ///< Pcode injection manager- RangeList nohighptr; ///< Ranges for which high-level pointers are not possibleCommentDatabase *commentdb; ///< Comments for this architectureStringManager *stringManager; ///< Manager of decoded stringsConstantPool *cpool; ///< Deferred constant values@@ -225,7 +224,6 @@ public:ProtoModel *getModel(const string &nm) const; ///< Get a specific PrototypeModelbool hasModel(const string &nm) const; ///< Does this Architecture have a specific PrototypeModelProtoModel *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 registerconst LanedRegister *getLanedRegister(const Address &loc,int4 size) const; ///< Get LanedRegister associated with storageint4 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 architecturevirtual 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#endifdiff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/coreaction.ccindex 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 usepointMapEntry *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.ccindex 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) constelse 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.ccindex 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 jusres = Address(spaceid,addressbase); // Get base address of the slotspaceused = 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 returnedif (curEntry.isExclusion()) {const vector<int4> &groupSet(curEntry.getAllGroups());@@ -892,7 +892,7 @@ void ParamListStandard::buildTrialMap(ParamActive *active) constcontinue;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 ¶mtrial(active->getTrial(trialpos));@@ -923,7 +923,7 @@ void ParamListStandard::buildTrialMap(ParamActive *active) constfor(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 ¶mtrial(active->getTrial(trialpos));@@ -1451,6 +1451,7 @@ void ParamListStandard::getRangeList(AddrSpace *spc,RangeList &res) constvoid 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 paramrangeset<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.hhindex 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 entryuintb 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 overlapbool 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 resolverlist<ModelRule> modelRules; ///< Rules to apply when assigning addressesAddrSpace *spacebase; ///< Address space containing relative offset parameters+ const AddrSpaceManager *glb; ///< Owning managerconst ParamEntry *findEntry(const Address &loc,int4 size,bool just) const; ///< Given storage location find matching ParamEntryconst ParamEntry *selectUnreferenceEntry(int4 grp,type_class prefType) const; ///< Select entry to fill an unreferenced paramvoid buildTrialMap(ParamActive *active) const; ///< Build map from parameter trials to model ParamEntrys@@ -618,6 +619,7 @@ public:ParamListStandard(const ParamListStandard &op2); ///< Copy constructorvirtual ~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 ownerbool isBigEndian(void) const { return entry.front().getSpace()->isBigEndian(); } ///< Return \b true if resources are big endianvoid extractTiles(vector<const ParamEntry *> &tiles,type_class type) const; ///< Get registers of given storage classconst ParamEntry *getStackEntry(void) const; ///< Get the stack entrydiff --git a/Ghidra/Features/Decompiler/src/decompile/cpp/heritage.cc b/Ghidra/Features/Decompiler/src/decompile/cpp/heritage.ccindex 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.ccindex 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,iif (tmpStatus[entry->getGroup()] != 0)continue; // Already consumedint4 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 registerpieces.push_back(VarnodeData());pieces.back().space = addr.getSpace();@@ -871,7 +871,8 @@ uint4 MultiSlotAssign::assignAddress(Datatype *dt,const PrototypePieces &proto,iif (!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 &proentry = 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 registerpieces.push_back(VarnodeData());pieces.back().space = addr.getSpace();@@ -1221,7 +1222,8 @@ uint4 MultiSlotDualAssign::assignAddress(Datatype *dt,const PrototypePieces &proif (!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.ccindex 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 sflags |= (heritaged | does_deadcode); // Always on unless explicitly turned off in derived constructorcalcScaleMask();+ 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) consts << "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 preturn -1;pointOffset = pointSpace->wrapOffset(pointOffset + pointSkip);}- JoinRecord *joinRecord = getManager()->findJoin(offset);+ JoinRecord *joinRecord = manage->findJoin(offset);// Set up so we traverse pieces in data orderint4 startPiece,endPiece,dir;if (isBigEndian()) {@@ -502,7 +515,7 @@ int4 JoinSpace::overlapJoin(uintb offset,int4 size,AddrSpace *pointSpace,uintb pvoid JoinSpace::encodeAttributes(Encoder &encoder,uintb offset) const{- JoinRecord *rec = getManager()->findJoin(offset); // Record must already exist+ JoinRecord *rec = manage->findJoin(offset); // Record must already existencoder.writeSpace(ATTRIB_SPACE, this);int4 num = rec->numPieces();if (num > MAX_PIECES)@@ -572,7 +585,7 @@ uintb JoinSpace::decodeAttributes(Decoder &decoder,uint4 &size) constif (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) constvoid 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 existchar 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.hhindex 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 itis_otherspace = 0x400, ///< Quick check for the OtherSpace derived classhas_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 spaceconst 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 spaceuint4 flags; ///< Attributes of the space+ char shortcut; ///< Shortcut character for printinguintb highest; ///< Highest (byte) offset into this spaceuintb pointerLowerBound; ///< Offset below which we don't search for pointersuintb pointerUpperBound; ///< Offset above which we don't search for pointers- char shortcut; ///< Shortcut character for printingprotected:+ AddrSpaceManager *manage; ///< Manager for processor using this spacestring name; ///< Name of this spaceuint4 addressSize; ///< Size of an address into this space in bytesuint4 wordsize; ///< Size of unit being addressed (1=byte)@@ -126,7 +131,6 @@ public:AddrSpace(AddrSpaceManager *m,const Translate *t,spacetype tp); ///< For use with decodevirtual ~AddrSpace(void) {} ///< The address space destructorconst string &getName(void) const; ///< Get the name- AddrSpaceManager *getManager(void) const; ///< Get the space managerconst Translate *getTrans(void) const; ///< Get the processor translatorspacetype getType(void) const; ///< Get the type of spaceint4 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 spacebool isOtherSpace(void) const; ///< Return \b true if \b this is the \e other address spacebool 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 spacebool hasNearPointers(void) const; ///< Return \b true if \e near (truncated) pointers into \b this space are possiblebool allowsWrappedRange(void) const; ///< Return \b true if memory range can span high to low addresses in \b this spacevoid 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 spacevirtual int4 numSpacebase(void) const; ///< Number of base registers associated with this spacevirtual 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.ccindex 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 uint1if (numChars < 0)return 0; // Not a legal encodinguint8 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.ccindex 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 Varnobasespace->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 valueAddress 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 rangeAddress 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.hhindex 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 variablesAddrSpace *stackspace; ///< Stack space associated with processorAddrSpace *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 addressprotected:AddrSpace *decodeSpace(Decoder &decoder,const Translate *trans); ///< Add a space to the model based an on XML tagvoid 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 modelvoid copySpaces(const AddrSpaceManager *op2); ///< Copy spaces from another managervoid 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 existvoid insertResolver(AddrSpace *spc,AddressResolver *rsolv); ///< Override the base resolver for a spacevoid setInferPtrBounds(const Range &range); ///< Set the range of addresses that can be inferred as pointersJoinRecord *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 storedAddrSpace *getConstantSpace(void) const; ///< Get the constant spaceAddress 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 spaceAddress 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 processorAddrSpace *getSpace(int4 i) const; ///< Get an address space via its indexAddrSpace *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 piecesJoinRecord *findJoin(uintb offset) const; ///< Find JoinRecord for \e offset in the join spacevoid setDeadcodeDelay(AddrSpace *spc,int4 delaydelta); ///< Set the deadcodedelay for a specific spacevoid 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 morediff --git a/Ghidra/Processors/RISCV/data/languages/riscv32-fp.cspec b/Ghidra/Processors/RISCV/data/languages/riscv32-fp.cspecindex 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.cspecindex 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>