ROSE  0.9.10.95
BinaryCallingConvention.h
1 #ifndef ROSE_BinaryAnalysis_CallingConvention_H
2 #define ROSE_BinaryAnalysis_CallingConvention_H
3 
4 #include <BaseSemantics2.h>
5 #include <BinaryStackVariable.h>
6 #include <Partitioner2/BasicTypes.h>
7 #include <RegisterParts.h>
8 
9 #include <boost/serialization/access.hpp>
10 #include <boost/serialization/set.hpp>
11 #include <boost/serialization/string.hpp>
12 #include <boost/serialization/vector.hpp>
13 #include <Sawyer/SharedObject.h>
14 #include <Sawyer/SharedPointer.h>
15 
16 namespace Rose {
17 namespace BinaryAnalysis {
18 
19 // Forwards
20 class Disassembler;
21 
32 namespace CallingConvention {
33 
37 void initDiagnostics();
38 
43 
45 // Miscellaneous small types
47 
53 };
54 
59 };
60 
66 };
67 
68 
70 // ParameterLocation
72 
82  #undef ABSOLUTE
84 public:
86  enum Type {
91  };
92 
93 private:
94  Type type_;
95  RegisterDescriptor reg_; // The argument register, or the stack base register.
96  union {
97  int64_t offset_; // Offset from stack base register for stack-based locations.
98  rose_addr_t va_; // Absolute address
99  };
100 
101 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
102 private:
103  friend class boost::serialization::access;
104 
105  template<class S>
106  void serialize(S &s, const unsigned /*version*/) {
107  s & BOOST_SERIALIZATION_NVP(type_);
108  s & BOOST_SERIALIZATION_NVP(reg_);
109  if (STACK==type_) {
110  s & BOOST_SERIALIZATION_NVP(offset_);
111  } else {
112  s & BOOST_SERIALIZATION_NVP(va_);
113  }
114  }
115 #endif
116 
117 public:
124  : type_(NO_LOCATION), offset_(0) {}
125 
128  : type_(REGISTER), reg_(reg), offset_(0) {}
129 
132  : type_(STACK), reg_(reg), offset_(offset) {}
133 
135  explicit ParameterLocation(rose_addr_t va)
136  : type_(ABSOLUTE), va_(va) {}
137 
139  Type type() const { return type_; }
140 
144  bool isValid() const {
145  return type() != NO_LOCATION;
146  }
147 
154  return reg_;
155  }
156 
162  int64_t offset() const {
163  return STACK == type_ ? offset_ : (int64_t)0;
164  }
165 
170  rose_addr_t address() const {
171  return ABSOLUTE == type_ ? va_ : (rose_addr_t)0;
172  }
173 
177  bool operator==(const ParameterLocation &other) const {
178  return type_ == other.type_ && reg_ == other.reg_ && offset_ == other.offset_; // &va_ == &offset_
179  }
180 
184  bool operator!=(const ParameterLocation &other) const {
185  return type_ != other.type_ || reg_ != other.reg_ || offset_ != other.offset_; // &va_ == &offset_
186  }
187 
191  void print(std::ostream &out, const RegisterDictionary *regdict) const {
192  print(out, RegisterNames(regdict));
193  }
194  void print(std::ostream &out, const RegisterNames &regnames) const {
195  switch (type_) {
196  case NO_LOCATION: out <<"nowhere"; break;
197  case REGISTER: out <<regnames(reg_); break;
198  case STACK: out <<"mem[" <<regnames(reg_) <<"+" <<offset_ <<"]"; break;
199  case ABSOLUTE: out <<"mem[" <<StringUtility::addrToString(va_) <<"]"; break;
200  }
201  }
204 };
205 
206 
208 // Definition
210 
213 
218 public:
221 
222 private:
223  std::string name_; // Official short name of the convention, like "stdcall".
224  std::string comment_; // Long name, like "Windows Borland x86-32 fastcall"
225  size_t wordWidth_; // Natural width word size in bits
226  const RegisterDictionary *regDict_; // Register dictionary used when this definition was created
227  std::vector<ParameterLocation> inputParameters_; // Input (inc. in-out) parameters; additional stack-based are implied
228  std::vector<ParameterLocation> outputParameters_; // Return values and output parameters.
229  StackParameterOrder stackParameterOrder_; // Order of arguments on the stack
230  RegisterDescriptor stackPointerRegister_; // Base pointer for implied stack parameters
231  size_t nonParameterStackSize_; // Size in bytes of non-parameter stack area
232  size_t stackAlignment_; // Stack alignment in bytes (zero means unknown)
233  StackDirection stackDirection_; // Direction that stack grows from a PUSH operation
234  StackCleanup stackCleanup_; // Who cleans up stack parameters?
235  ParameterLocation thisParameter_; // Object pointer for calling conventions that are object methods
236  std::set<RegisterDescriptor> calleeSavedRegisters_; // Register that the callee must restore before returning
237  std::set<RegisterDescriptor> scratchRegisters_; // Caller-saved registers
238 
239 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
240 private:
241  friend class boost::serialization::access;
242 
243  template<class S>
244  void serialize(S &s, const unsigned /*version*/) {
245  s & BOOST_SERIALIZATION_NVP(name_);
246  s & BOOST_SERIALIZATION_NVP(comment_);
247  s & BOOST_SERIALIZATION_NVP(wordWidth_);
248  s & BOOST_SERIALIZATION_NVP(regDict_);
249  s & BOOST_SERIALIZATION_NVP(inputParameters_);
250  s & BOOST_SERIALIZATION_NVP(outputParameters_);
251  s & BOOST_SERIALIZATION_NVP(stackParameterOrder_);
252  s & BOOST_SERIALIZATION_NVP(stackPointerRegister_);
253  s & BOOST_SERIALIZATION_NVP(nonParameterStackSize_);
254  s & BOOST_SERIALIZATION_NVP(stackAlignment_);
255  s & BOOST_SERIALIZATION_NVP(stackDirection_);
256  s & BOOST_SERIALIZATION_NVP(stackCleanup_);
257  s & BOOST_SERIALIZATION_NVP(thisParameter_);
258  s & BOOST_SERIALIZATION_NVP(calleeSavedRegisters_);
259  s & BOOST_SERIALIZATION_NVP(scratchRegisters_);
260  }
261 #endif
262 
263 protected:
268  : wordWidth_(0), regDict_(NULL), stackParameterOrder_(ORDER_UNSPECIFIED), nonParameterStackSize_(0),
269  stackAlignment_(0), stackDirection_(GROWS_DOWN), stackCleanup_(CLEANUP_UNSPECIFIED) {}
270 
276  Definition(size_t wordWidth, const std::string &name, const std::string &comment, const RegisterDictionary *regDict)
277  : name_(name), comment_(comment), wordWidth_(wordWidth), regDict_(regDict), stackParameterOrder_(ORDER_UNSPECIFIED),
278  nonParameterStackSize_(0), stackAlignment_(0), stackDirection_(GROWS_DOWN), stackCleanup_(CLEANUP_UNSPECIFIED) {
279  ASSERT_require2(0 == (wordWidth & 7) && wordWidth > 0, "word size must be a positive multiple of eight");
280  }
281 
282 public:
284  static Ptr instance(size_t wordWidth, const std::string &name, const std::string &comment, const RegisterDictionary *regs) {
285  return Ptr(new Definition(wordWidth, name, comment, regs));
286  }
287 
288 public:
292  static Ptr x86_32bit_cdecl();
293  static Ptr x86_64bit_cdecl();
294  static Ptr x86_32bit_stdcall();
295  static Ptr x86_64bit_stdcall();
296  static Ptr x86_32bit_fastcall();
297  static Ptr x86_64bit_sysv();
298  static Ptr ppc_32bit_ibm();
304  static Ptr x86_cdecl(const RegisterDictionary*);
305  static Ptr x86_stdcall(const RegisterDictionary*);
306  static Ptr x86_fastcall(const RegisterDictionary*);
307  static Ptr ppc_ibm(const RegisterDictionary*);
315  const RegisterDictionary* registerDictionary() const { return regDict_; }
316  void registerDictionary(const RegisterDictionary *d) { regDict_ = d; }
327  const std::string& name() const { return name_; }
328  void name(const std::string &s) { name_ = s; }
338  const std::string& comment() const { return comment_; }
339  void comment(const std::string &s) { comment_ = s; }
351  size_t wordWidth() const { return wordWidth_; }
352  void wordWidth(size_t nBits) {
353  ASSERT_require2(nBits > 0 && 0 == (nBits & 7), "word size must be a positive multiple of eight");
354  wordWidth_ = nBits;
355  }
364  thisParameter_ = ParameterLocation();
365  }
366 
371  const std::vector<ParameterLocation>& inputParameters() const { return inputParameters_; }
372 
375 
380  void clearInputParameters() { inputParameters_.clear(); }
381 
391  }
392  void appendInputParameter(RegisterDescriptor reg, int64_t offset) {
394  }
395  void appendInputParameter(rose_addr_t va) {
397  }
404  const std::vector<ParameterLocation>& outputParameters() const { return outputParameters_; }
405 
408 
413  void clearOutputParameters() { outputParameters_.clear(); }
414 
426  }
427  void appendOutputParameter(RegisterDescriptor reg, int64_t offset) {
429  }
430  void appendOutputParameter(rose_addr_t va) {
432  }
445  StackParameterOrder stackParameterOrder() const { return stackParameterOrder_; }
446  void stackParameterOrder(StackParameterOrder x) { stackParameterOrder_ = x; }
456  const RegisterDescriptor stackPointerRegister() const { return stackPointerRegister_; }
457  void stackPointerRegister(RegisterDescriptor r) { stackPointerRegister_ = r; }
467  size_t nonParameterStackSize() const {
468  return nonParameterStackSize_;
469  }
470  void nonParameterStackSize(size_t nBytes) {
471  nonParameterStackSize_ = nBytes;
472  }
482  StackDirection stackDirection() const { return stackDirection_; }
483  void stackDirection(StackDirection x) { stackDirection_ = x; }
493  StackCleanup stackCleanup() const { return stackCleanup_; }
494  void stackCleanup(StackCleanup x) { stackCleanup_ = x; }
503  size_t stackAlignment() const { return stackAlignment_; }
504  void stackAlignment(size_t nBytes) { stackAlignment_ = nBytes; }
521  const ParameterLocation& thisParameter() const { return thisParameter_; }
522  void thisParameter(const ParameterLocation &x) { thisParameter_ = x; }
525  }
526  void thisParameter(RegisterDescriptor reg, int64_t offset) {
527  thisParameter(ParameterLocation(reg, offset));
528  }
529  void thisParameter(rose_addr_t va) {
531  }
545  const std::set<RegisterDescriptor>& calleeSavedRegisters() const { return calleeSavedRegisters_; }
546  std::set<RegisterDescriptor>& calleeSavedRegisters() { return calleeSavedRegisters_; }
551 
559  const std::set<RegisterDescriptor>& scratchRegisters() const { return scratchRegisters_; }
560  std::set<RegisterDescriptor>& scratchRegisters() { return scratchRegisters_; }
565 
576 
581  void print(std::ostream&, const RegisterDictionary *regDict = NULL) const;
582 
584  // Deprecated API
585  //
586  // This is mostly here for backward compatibility with the original API design, which was then implemented in SEI's pharos
587  // library. Unless otherwise noted, these were all deprecated as of 2015-08-14 in favor of CamelCase and dropping the
588  // "get" and "set" from properties that have names that are nouns.
590 public:
591  size_t get_word_size() const ROSE_DEPRECATED("use wordWidth property instead") {
592  return wordWidth();
593  }
594  void set_word_size(size_t w) ROSE_DEPRECATED("use wordWidth property instead") {
595  wordWidth(w);
596  }
597 
598  const std::string& get_name() const ROSE_DEPRECATED("use \"name\" property instead") {
599  return name();
600  }
601  void set_name(const std::string &n) ROSE_DEPRECATED("use \"name\" property instead") {
602  name(n);
603  }
604 
605  // The comment property stores a full name without any particular format. It may or may not include the compiler name
606  // depending on whether the compiler name is significant. If it includes a compiler name, it may or may not include a
607  // compiler version.
608  const std::string &get_compiler() const ROSE_DEPRECATED("use \"comment\" property instead") {
609  return comment();
610  }
611  void set_compiler(const std::string &c) ROSE_DEPRECATED("use \"comment\" property instead") {
612  comment(c);
613  }
614 
615  const std::string &get_comment() const ROSE_DEPRECATED("use \"comment\" property instead") {
616  return comment();
617  }
618  void set_comment(const std::string &c) ROSE_DEPRECATED("use \"comment\" property instead") {
619  comment(c);
620  }
621 
622  enum ParameterOrder {/*NO_STRINGIFY*/
623  ORDER_LTR = LEFT_TO_RIGHT,
624  ORDER_RTL = RIGHT_TO_LEFT,
625  ORDER_UNKNOWN = ORDER_UNSPECIFIED,
626  };
627 
628  ParameterOrder get_param_order() const ROSE_DEPRECATED("use stackParameterOrder property instead") {
629  return (ParameterOrder)stackParameterOrder();
630  }
631  void set_param_order(ParameterOrder order) ROSE_DEPRECATED("use stackParameterOrder property instead") {
633  }
634 
635  enum ThisPointerLocation {/*NO_STRINGIFY*/
636  THIS_FIRST_PARAM,
637  THIS_REGISTER,
638  THIS_NOT_APPLICABLE,
639  THIS_UNKNOWN,
640  };
641 
642  ThisPointerLocation get_this_location() const ROSE_DEPRECATED("use thisParameter property instead") {
643  const ParameterLocation &loc = thisParameter();
644  switch (loc.type()) {
645  case ParameterLocation::NO_LOCATION: return THIS_NOT_APPLICABLE; // or maybe THIS_UNKNOWN
646  case ParameterLocation::REGISTER: return THIS_REGISTER;
647  case ParameterLocation::STACK: return THIS_FIRST_PARAM; // assume its the first parameter
648  case ParameterLocation::ABSOLUTE: return THIS_UNKNOWN; // not supported in old API
649  }
650  ASSERT_not_reachable("invalid location type");
651  }
652  // We can't set the location type independent of the location.
653  //void set_this_location(ThisPointerLocation loc) ROSE_DEPRECATED("use thisParameter property instead") {
654 
655  void set_this_register(const RegisterDescriptor *reg) ROSE_DEPRECATED("use thisParameter property instead") {
656  if (NULL == reg) {
657  thisParameter(ParameterLocation()); // no location
658  } else {
659  thisParameter(*reg);
660  }
661  }
662 
663  enum ReturnValueLocation {/*NO_STRINGIFY*/
664  RETVAL_STACK,
665  RETVAL_REGISTER,
666  RETVAL_NOT_APPLICABLE,
667  RETVAL_UNKNOWN,
668  };
669 
670  ReturnValueLocation get_retval_location() const ROSE_DEPRECATED("use outputParameters property instead") {
671  if (outputParameters().empty())
672  return RETVAL_NOT_APPLICABLE;
673  const ParameterLocation &loc = outputParameters().front();
674  switch (loc.type()) {
675  case ParameterLocation::NO_LOCATION: return RETVAL_UNKNOWN;
676  case ParameterLocation::REGISTER: return RETVAL_REGISTER;
677  case ParameterLocation::STACK: return RETVAL_STACK;
678  case ParameterLocation::ABSOLUTE: return RETVAL_UNKNOWN; // not supported in old API
679  }
680  ASSERT_not_reachable("invalid return value location");
681  }
682  // We can't set the return value location type independent of the location.
683  // void set_retval_location(ReturnValueLocation loc) ROSE_DEPRECATED("use appendOutputParameter instead");
684 
685  void set_retval_register(const RegisterDescriptor *reg) ROSE_DEPRECATED("use appendOutputParameter instead") {
687  if (NULL != reg)
688  appendOutputParameter(*reg);
689  }
690 
691  StackCleanup get_stack_cleanup() const ROSE_DEPRECATED("use stackCleanup property instead") {
692  return stackCleanup();
693  }
694  void set_stack_cleanup(StackCleanup cleanup) ROSE_DEPRECATED("use stackCleanup property instead") {
695  stackCleanup(cleanup);
696  }
697 
698  // These aren't needed for disassembly, only for compilers.
699  //size_t get_stack_alignment() const { return stack_alignment; }
700  //void set_stack_alignment(size_t alignment) { stack_alignment = alignment; }
701 
702  typedef std::vector<RegisterDescriptor> RegisterVector;
703 
704  // We can't return a reference like the original API because this object doesn't keep a vector of just the register
705  // parameters.
706  RegisterVector get_reg_params() const ROSE_DEPRECATED("use inputParameters property instead") {
707  RegisterVector retval;
708  BOOST_FOREACH (const ParameterLocation &loc, inputParameters_) {
709  if (loc.type() == ParameterLocation::REGISTER)
710  retval.push_back(loc.reg());
711  }
712  return retval;
713  }
714  void add_reg_param(const RegisterDescriptor *reg) ROSE_DEPRECATED("use appendInputParameter instead") {
716  }
717 
718  typedef std::set<RegisterDescriptor> RegisterSet;
719 
720  const RegisterSet& get_nonvolatile() const ROSE_DEPRECATED("use calleeSavedRegisters property instead") {
721  return calleeSavedRegisters();
722  }
723  void add_nonvolatile(const RegisterDictionary *dict, const std::string &name)
724  ROSE_DEPRECATED("use calleeSavedRegisters property instead") {
725  const RegisterDescriptor *rd = dict->lookup(name);
726  ASSERT_not_null2(rd, "unable to find register \"" + StringUtility::cEscape(name) + "\"");
727  calleeSavedRegisters().insert(*rd);
728  }
729  void add_nonvolatile(const RegisterDescriptor *rd) ROSE_DEPRECATED("use calleeSavedRegisters property instead") {
730  ASSERT_require2(rd && rd->is_valid(), "invalid nonvolatile register");
731  calleeSavedRegisters().insert(*rd);
732  }
733  void add_nonvolatile(const RegisterSet &regs) ROSE_DEPRECATED("use calleeSavedRegisters property instead") {
734  calleeSavedRegisters().insert(regs.begin(), regs.end());
735  }
736 
737  // Write information about this calling convention to the debug log stream.
738  void report(const RegisterDictionary *regdict) const ROSE_DEPRECATED("use \"print\" instead") {
739  print(std::cout, regdict);
740  };
741 };
742 
743 
745 // Dictionary
747 
749 typedef std::vector<Definition::Ptr> Dictionary;
750 
752 const Dictionary& dictionaryAmd64();
753 
755 const Dictionary& dictionaryArm();
756 
758 const Dictionary& dictionaryM68k();
759 
761 const Dictionary& dictionaryMips();
762 
764 const Dictionary& dictionaryPowerpc();
765 
767 const Dictionary& dictionaryX86();
768 
769 
771 // Analysis
773 
777 class Analysis {
778 private:
780  const RegisterDictionary *regDict_; // Names for the register parts
781  Definition::Ptr defaultCc_; // Default calling convention for called functions
782 
783  bool hasResults_; // Are the following data members initialized?
784  bool didConverge_; // Are the following data members valid (else only approximations)?
785  RegisterParts restoredRegisters_; // Registers accessed but restored
786  RegisterParts inputRegisters_; // Registers that serve as possible input parameters
787  RegisterParts outputRegisters_; // Registers that hold possible return values
788  StackVariables inputStackParameters_; // Stack variables serving as function inputs
789  StackVariables outputStackParameters_; // Stack variables serving as possible return values
790  Sawyer::Optional<int64_t> stackDelta_; // Change in stack across entire function
791  // Don't forget to update clearResults() and serialize() if you add more.
792 
793 #ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
794 private:
795  friend class boost::serialization::access;
796 
797  template<class S>
798  void serialize(S &s, const unsigned /*version*/) {
799  s & BOOST_SERIALIZATION_NVP(cpu_);
800  s & BOOST_SERIALIZATION_NVP(regDict_);
801  s & BOOST_SERIALIZATION_NVP(defaultCc_);
802  s & BOOST_SERIALIZATION_NVP(hasResults_);
803  s & BOOST_SERIALIZATION_NVP(didConverge_);
804  s & BOOST_SERIALIZATION_NVP(restoredRegisters_);
805  s & BOOST_SERIALIZATION_NVP(inputRegisters_);
806  s & BOOST_SERIALIZATION_NVP(outputRegisters_);
807  s & BOOST_SERIALIZATION_NVP(inputStackParameters_);
808  s & BOOST_SERIALIZATION_NVP(outputStackParameters_);
809  s & BOOST_SERIALIZATION_NVP(stackDelta_);
810  }
811 #endif
812 
813 public:
820  : regDict_(NULL), hasResults_(false), didConverge_(false) {}
821 
825  explicit Analysis(Disassembler *d)
826  : regDict_(NULL), hasResults_(false), didConverge_(false) {
827  init(d);
828  }
829 
837  : cpu_(cpu), regDict_(NULL), hasResults_(false), didConverge_(false) {}
838 
846  Definition::Ptr defaultCallingConvention() const { return defaultCc_; }
847  void defaultCallingConvention(const Definition::Ptr &x) { defaultCc_ = x; }
856 
861  bool hasResults() const { return hasResults_; }
862 
867  bool didConverge() const { return didConverge_; }
868 
873  void clearResults();
874 
879  void clearNonResults();
880 
888  const RegisterDictionary* registerDictionary() const { return regDict_; }
889  void registerDictionary(const RegisterDictionary *d) { regDict_ = d; }
896  const RegisterParts& calleeSavedRegisters() const { return restoredRegisters_; }
897 
902  const RegisterParts& inputRegisters() const { return inputRegisters_; }
903 
908  const RegisterParts& outputRegisters() const { return outputRegisters_; }
909 
913  const StackVariables& inputStackParameters() const { return inputStackParameters_; }
914 
918  const StackVariables& outputStackParameters() const { return outputStackParameters_; }
919 
924  Sawyer::Optional<int64_t> stackDelta() const { return stackDelta_; }
925 
929  bool match(const Definition::Ptr&) const;
930 
936  Dictionary match(const Dictionary&) const;
937 
942  void print(std::ostream&, bool multiLine=false) const;
943 
944 private:
945  // Finish constructing
946  void init(Disassembler*);
947 
948  // Recompute the restoredRegisters_ data member.
949  void updateRestoredRegisters(const InstructionSemantics2::BaseSemantics::StatePtr &initialState,
951 
952  // Recompute the inputRegisters_ data member after updateRestoredRegisters is computed.
953  void updateInputRegisters(const InstructionSemantics2::BaseSemantics::StatePtr &state);
954 
955  // Recompute the outputRegisters_ data member after updateRestoredRegisters is computed.
956  void updateOutputRegisters(const InstructionSemantics2::BaseSemantics::StatePtr &state);
957 
958  // Recompute the input and output stack variables
959  void updateStackParameters(const InstructionSemantics2::BaseSemantics::StatePtr &initialState,
961 
962  // Recomputes the stack delta
963  void updateStackDelta(const InstructionSemantics2::BaseSemantics::StatePtr &initialState,
965 };
966 
968 // Free functions
970 
971 std::ostream& operator<<(std::ostream&, const Definition&);
972 std::ostream& operator<<(std::ostream&, const Analysis&);
973 
974 } // namespace
975 } // namespace
976 } // namespace
977 
978 #endif
void print(std::ostream &out, const RegisterNames &regnames) const
Print location.
void thisParameter(rose_addr_t va)
Property: Object pointer parameter.
size_t wordWidth() const
Property: Word size in bits.
const Dictionary & dictionaryX86()
Common calling conventions for 32-bit x86.
const std::vector< ParameterLocation > & outputParameters() const
Property: List of output parameters.
void registerDictionary(const RegisterDictionary *d)
Property: Register dictionary.
StackParameterOrder stackParameterOrder() const
Property: Stack parameter order.
size_t stackAlignment() const
Property: Stack alignment.
const Dictionary & dictionaryM68k()
Common calling conventions for m68k.
void print(std::ostream &out, const RegisterDictionary *regdict) const
Print location.
StackDirection stackDirection() const
Property: Direction that stack grows for a push operation.
The called function pops all stack parameters.
void wordWidth(size_t nBits)
Property: Word size in bits.
void stackDirection(StackDirection x)
Property: Direction that stack grows for a push operation.
void appendInputParameter(const ParameterLocation &)
Append input parameter.
const Dictionary & dictionaryArm()
Common calling conventions for ARM.
std::vector< StackVariable > StackVariables
Multiple stack variables.
RegisterDescriptor reg() const
Register part of location.
static Ptr x86_32bit_cdecl()
Returns a predefined, cached calling convention.
const RegisterDictionary * registerDictionary() const
Property: Register dictionary.
void appendOutputParameter(rose_addr_t va)
Append output parameter.
Sawyer::SharedPointer< class Definition > DefinitionPtr
Reference counting pointer to calling convention definition.
void registerDictionary(const RegisterDictionary *d)
Property: Register dictionary.
Collection of streams.
Definition: Message.h:1579
static Ptr x86_32bit_stdcall()
Allocating constructor.
static Ptr ppc_32bit_ibm()
Allocating constructor.
void thisParameter(RegisterDescriptor reg, int64_t offset)
Property: Object pointer parameter.
ParameterLocation(RegisterDescriptor reg)
Constructs a parameter in a register location.
ParameterLocation(RegisterDescriptor reg, int64_t offset)
Constructs a parameter at a register-relative memory address.
void thisParameter(const ParameterLocation &x)
Property: Object pointer parameter.
StackDirection
The direction in which the stack grows.
Analysis(Disassembler *d)
Construct an analyzer using a specified disassembler.
bool operator!=(const ParameterLocation &other) const
Inequality.
const Dictionary & dictionaryAmd64()
Common calling conventions for amd64 (x86-64).
void appendInputParameter(rose_addr_t va)
Append input parameter.
Definition::Ptr defaultCallingConvention() const
Property: Default calling convention.
void thisParameter(RegisterDescriptor reg)
Property: Object pointer parameter.
void stackCleanup(StackCleanup x)
Property: Who pops stack parameters.
rose_addr_t address() const
Fixed address location.
Main namespace for the ROSE library.
RegisterParts inputRegisterParts() const
Compute the set of input registers.
RegisterParts scratchRegisterParts() const
Computes the set of scratch registers.
Describes (part of) a physical CPU register.
Holds a set of registers without regard for register boundaries.
Definition: RegisterParts.h:25
StackCleanup stackCleanup() const
Property: Who pops stack parameters.
static Ptr x86_fastcall(const RegisterDictionary *)
Constructs a new pre-defined calling convention based on a register dictionary.
Sawyer::Optional< int64_t > stackDelta() const
Concrete stack delta.
bool hasResults() const
Whether a function has been analyzed.
Sawyer::SharedPointer< Definition > Ptr
Reference counting pointer to calling convention definition.
const ParameterLocation & thisParameter() const
Property: Object pointer parameter.
ROSE_UTIL_API std::string cEscape(const std::string &)
Escapes characters that are special to C/C++.
boost::shared_ptr< class State > StatePtr
Shared-ownership pointer to a semantic state.
void comment(const std::string &s)
Property: Full name of calling convention.
const RegisterParts & calleeSavedRegisters() const
Callee-saved registers.
void stackParameterOrder(StackParameterOrder x)
Property: Stack parameter order.
const RegisterParts & inputRegisters() const
Input registers.
boost::shared_ptr< class Dispatcher > DispatcherPtr
Shared-ownership pointer to a semantics instruction dispatcher.
void print(std::ostream &, bool multiLine=false) const
Print information about the analysis results.
bool operator==(const ParameterLocation &other) const
Equality.
std::vector< Definition::Ptr > Dictionary
A ordered collection of calling convention definitions.
const Dictionary & dictionaryMips()
Common calling conventions for MIPS.
void appendOutputParameter(const ParameterLocation &)
Append output parameter.
static Ptr x86_cdecl(const RegisterDictionary *)
Constructs a new pre-defined calling convention based on a register dictionary.
static Ptr instance(size_t wordWidth, const std::string &name, const std::string &comment, const RegisterDictionary *regs)
Allocating constructor.
const std::set< RegisterDescriptor > & calleeSavedRegisters() const
Property: Callee-saved registers.
void appendInputParameter(RegisterDescriptor reg)
Append input parameter.
ROSE_UTIL_API std::string addrToString(uint64_t value, size_t nbits=0)
Convert a virtual address to a string.
void nonParameterStackSize(size_t nBytes)
Property: Size of non-parameter stack area.
StackParameterOrder
The order that arguments are pushed onto the stack.
bool isValid() const
Predicate to determine if location is valid.
bool didConverge() const
Whether the analysis results are valid.
std::set< RegisterDescriptor > & scratchRegisters()
Property: Scratch registers.
Sawyer::Message::Facility mlog
Facility for diagnostic output.
void appendInputParameter(RegisterDescriptor reg, int64_t offset)
Append input parameter.
void analyzeFunction(const Partitioner2::Partitioner &, const Sawyer::SharedPointer< Partitioner2::Function > &)
Analyze one function.
void print(std::ostream &, const RegisterDictionary *regDict=NULL) const
Print detailed information about this calling convention.
size_t nonParameterStackSize() const
Property: Size of non-parameter stack area.
Analysis(const InstructionSemantics2::BaseSemantics::DispatcherPtr &cpu)
Construct an analysis using a specified dispatcher.
static Ptr x86_stdcall(const RegisterDictionary *)
Constructs a new pre-defined calling convention based on a register dictionary.
RegisterParts outputRegisterParts() const
Computes the set of output registers.
bool match(const Definition::Ptr &) const
Determine whether a definition matches.
Defines registers available for a particular architecture.
Definition: Registers.h:32
const RegisterDescriptor stackPointerRegister() const
Property: Register for implied stack parameters.
RegisterParts getUsedRegisterParts() const
Returns all registers mentioned in this definition.
const RegisterParts & outputRegisters() const
Output registers.
Prints a register name even when no dictionary is available or when the dictionary doesn't contain an...
Definition: Registers.h:354
static Ptr x86_64bit_cdecl()
Allocating constructor.
void name(const std::string &s)
Property: Short name of calling convention.
Stack parameters pushed left to right (Pascal order).
ParameterLocation(rose_addr_t va)
Constructs a parameter at a fixed memory address.
StackCleanup
Who is responsible for popping stack parameters.
const RegisterDictionary * registerDictionary() const
Property: Register dictionary.
Base class for reference counted objects.
Definition: SharedObject.h:22
void clearNonResults()
Clears everything but results.
void initDiagnostics()
Initialize diagnostics.
void clearResults()
Clear analysis results.
const std::vector< ParameterLocation > & inputParameters() const
Property: Enumerated input parameters.
Stack parameters pushed right to left (C order).
void clearInputParameters()
Erase enumerated input parameters.
void appendOutputParameter(RegisterDescriptor reg)
Append output parameter.
const std::string & name() const
Property: Short name of calling convention.
void stackAlignment(size_t nBytes)
Property: Stack alignment.
const Dictionary & dictionaryPowerpc()
Common calling conventions for PowerPC.
Stack parameter cleanup is unknown or unspecified.
Definition(size_t wordWidth, const std::string &name, const std::string &comment, const RegisterDictionary *regDict)
Allocating constructor.
Stack parameter order is unknown or unspecified.
const StackVariables & inputStackParameters() const
Input stack parameters.
RegisterParts calleeSavedRegisterParts() const
Compute the set of callee-saved registers.
void defaultCallingConvention(const Definition::Ptr &x)
Property: Default calling convention.
const std::string & comment() const
Property: Full name of calling convention.
const std::set< RegisterDescriptor > & scratchRegisters() const
Property: Scratch registers.
static Ptr x86_32bit_fastcall()
Allocating constructor.
Partitions instructions into basic blocks and functions.
Definition: Partitioner.h:293
static Ptr x86_64bit_sysv()
Allocating constructor.
Virtual base class for instruction disassemblers.
Definition: Disassembler.h:42
const StackVariables & outputStackParameters() const
Output stack parameters.
static Ptr x86_64bit_stdcall()
Allocating constructor.
std::set< RegisterDescriptor > & calleeSavedRegisters()
Property: Callee-saved registers.
static Ptr ppc_ibm(const RegisterDictionary *)
Constructs a new pre-defined calling convention based on a register dictionary.
void stackPointerRegister(RegisterDescriptor r)
Property: Register for implied stack parameters.
void appendOutputParameter(RegisterDescriptor reg, int64_t offset)
Append output parameter.