mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2025-10-04 18:29:37 +02:00
Merge remote-tracking branch 'origin/GP-2436_fixed_args_varargs'
This commit is contained in:
commit
d0f21f479a
3 changed files with 34 additions and 1 deletions
|
@ -1443,6 +1443,9 @@ void ActionFuncLink::funcLinkInput(FuncCallSpecs *fc,Funcdata &data)
|
|||
ProtoParameter *param = fc->getParam(i);
|
||||
active->registerTrial(param->getAddress(),param->getSize());
|
||||
active->getTrial(i).markActive(); // Parameter is not optional
|
||||
if (varargs){
|
||||
active->getTrial(i).setFixedPosition(i);
|
||||
}
|
||||
AddrSpace *spc = param->getAddress().getSpace();
|
||||
uintb off = param->getAddress().getOffset();
|
||||
int4 sz = param->getSize();
|
||||
|
|
|
@ -1701,6 +1701,25 @@ bool ParamTrial::operator<(const ParamTrial &b) const
|
|||
return (size < b.size);
|
||||
}
|
||||
|
||||
/// Sort by fixed position then by ParamTrial::operator<
|
||||
/// \param a trial
|
||||
/// \param b trial
|
||||
/// \return \b true if \b a should be ordered before \b b
|
||||
bool ParamTrial::fixedPositionCompare(const ParamTrial &a, const ParamTrial &b)
|
||||
|
||||
{
|
||||
if (a.fixedPosition == -1 && b.fixedPosition == -1){
|
||||
return a < b;
|
||||
}
|
||||
if (a.fixedPosition == -1){
|
||||
return false;
|
||||
}
|
||||
if (b.fixedPosition == -1){
|
||||
return true;
|
||||
}
|
||||
return a.fixedPosition < b.fixedPosition;
|
||||
}
|
||||
|
||||
/// \param recoversub selects whether a sub-function or the active function is being tested
|
||||
ParamActive::ParamActive(bool recoversub)
|
||||
|
||||
|
@ -5326,6 +5345,12 @@ void FuncCallSpecs::buildInputFromTrials(Funcdata &data)
|
|||
|
||||
newparam.push_back(op->getIn(0)); // Preserve the fspec parameter
|
||||
|
||||
if (isDotdotdot() && isInputLocked()){
|
||||
//if varargs, move the fixed args to the beginning of the list in order
|
||||
//preserve relative order of variable args
|
||||
activeinput.sortFixedPosition();
|
||||
}
|
||||
|
||||
for(int4 i=0;i<activeinput.getNumTrials();++i) {
|
||||
const ParamTrial ¶mtrial( activeinput.getTrial(i) );
|
||||
if (!paramtrial.isUsed()) continue; // Don't keep unused parameters
|
||||
|
|
|
@ -221,9 +221,10 @@ private:
|
|||
int4 slot; ///< Slot assigned to this trial
|
||||
const ParamEntry *entry; ///< PrototypeModel entry matching this trial
|
||||
int4 offset; ///< "justified" offset into entry
|
||||
int4 fixedPosition; ///< argument position if a fixed arg of a varargs function, else -1
|
||||
public:
|
||||
/// \brief Construct from components
|
||||
ParamTrial(const Address &ad,int4 sz,int4 sl) { addr = ad; size = sz; slot = sl; flags=0; entry=(ParamEntry *)0; offset=-1; }
|
||||
ParamTrial(const Address &ad,int4 sz,int4 sl) { addr = ad; size = sz; slot = sl; flags=0; entry=(ParamEntry *)0; offset=-1; fixedPosition = -1; }
|
||||
const Address &getAddress(void) const { return addr; } ///< Get the starting address of \b this trial
|
||||
int4 getSize(void) const { return size; } ///< Get the number of bytes in \b this trial
|
||||
int4 getSlot(void) const { return slot; } ///< Get the \e slot associated with \b this trial
|
||||
|
@ -259,6 +260,8 @@ public:
|
|||
ParamTrial splitLo(int4 sz) const; ///< Create a trial representing the last part of \b this
|
||||
bool testShrink(const Address &newaddr,int4 sz) const; ///< Test if \b this trial can be made smaller
|
||||
bool operator<(const ParamTrial &b) const; ///< Sort trials in formal parameter order
|
||||
void setFixedPosition(int4 pos) { fixedPosition = pos; } ///< Set fixed position
|
||||
static bool fixedPositionCompare(const ParamTrial &a, const ParamTrial &b); ///< Sort by fixed position; stable for fixedPosition = -1
|
||||
};
|
||||
|
||||
/// \brief Container class for ParamTrial objects
|
||||
|
@ -319,6 +322,8 @@ public:
|
|||
/// \param addr is the new range's starting address
|
||||
/// \param sz is the new range's size in bytes
|
||||
void shrink(int4 i,const Address &addr,int4 sz) { trial[i].setAddress(addr,sz); }
|
||||
|
||||
void sortFixedPosition(void) {sort(trial.begin(),trial.end(),ParamTrial::fixedPositionCompare);} ///< sort the trials by fixed position then <
|
||||
};
|
||||
|
||||
/// \brief A special space for encoding FuncCallSpecs
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue