ROSE 0.11.145.147
Definition.h
1#ifndef ROSE_BinaryAnalysis_CallingConvention_Definition_H
2#define ROSE_BinaryAnalysis_CallingConvention_Definition_H
3#include <featureTests.h>
4#ifdef ROSE_ENABLE_BINARY_ANALYSIS
5#include <Rose/BinaryAnalysis/CallingConvention/BasicTypes.h>
6
7#include <Rose/BinaryAnalysis/Architecture/BasicTypes.h>
8#include <Rose/BinaryAnalysis/Alignment.h>
9#include <Rose/BinaryAnalysis/ByteOrder.h>
10#include <Rose/BinaryAnalysis/ConcreteLocation.h>
11#include <Rose/BinaryAnalysis/RegisterDescriptor.h>
12
13#include <Sawyer/Optional.h>
14
15#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
16#include <boost/serialization/access.hpp>
17#endif
18
19#include <set>
20#include <string>
21#include <vector>
22
23namespace Rose {
24namespace BinaryAnalysis {
25namespace CallingConvention {
26
31public:
34
35private:
36 // General information
37 std::string name_; // Official short name of the convention, like "stdcall".
38 std::string comment_; // Long name, like "Windows Borland x86-32 fastcall"
39 Sawyer::Optional<size_t> bitsPerWord_; // Optionally override the word width from the architecture
40
41 // The architecture with which this calling convention definition is associated. It is referenced via weak pointer because the
42 // architecture typically contains a list of calling convention definitions, so if we had referred here to the architecture with
43 // a shared pointer we'd have a cycle. Architecture objects are typically not deleted since they're registered with the library.
44 std::weak_ptr<const Architecture::Base> architecture_;
45
46 // Used mostly during analysis
47 std::vector<ConcreteLocation> nonParameterInputs_; // Inputs that are not considered normal function parameters
48 std::vector<ConcreteLocation> inputParameters_; // Input (inc. in-out) parameters; additional stack-based are implied
49 std::vector<ConcreteLocation> outputParameters_; // Return values and output parameters.
50 StackParameterOrder stackParameterOrder_ = StackParameterOrder::UNSPECIFIED; // Order of arguments on the stack
51 RegisterDescriptor stackPointerRegister_; // Optionally override the stack pointerregister from the architecture
52 size_t nonParameterStackSize_ = 0; // Size in bytes of non-parameter stack area
53 Alignment stackAlignment_; // Stack alignment in bytes
54 StackDirection stackDirection_ = StackDirection::GROWS_DOWN; // Direction that stack grows from a PUSH operation
55 StackCleanup stackCleanup_ = StackCleanup::UNSPECIFIED; // Who cleans up stack parameters?
56 ConcreteLocation thisParameter_; // Object pointer for calling conventions that are object methods
57 std::set<RegisterDescriptor> calleeSavedRegisters_; // Register that the callee must restore before returning
58 std::set<RegisterDescriptor> scratchRegisters_; // Caller-saved registers
59 ConcreteLocation returnAddressLocation_; // Where is the function return address stored at function entry?
60 RegisterDescriptor instructionPointerRegister_; // Where is the next instruction address stored?
61
62 // These are used to figure out where function arguments and return values are stored given a function declaration. For
63 // instance, the first two arguments that are 32 bits wide get stored in register 1 and register 2, and other arguments are
64 // stored on the stack.
65 AllocatorPtr returnValueAllocator_;
66 AllocatorPtr argumentValueAllocator_;
67
68protected:
69#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
70 friend class boost::serialization::access;
71 template<class S> void serialize(S&, unsigned);
72#endif
73
78
84 Definition(const std::string &name, const std::string &comment, const Architecture::BaseConstPtr&);
85
86public:
88
89public:
91 static Ptr instance(const std::string &name, const std::string &comment, const Architecture::BaseConstPtr&);
92
93public:
100
105
114 const std::string& name() const { return name_; }
115 void name(const std::string &s) { name_ = s; }
125 const std::string& comment() const { return comment_; }
126 void comment(const std::string &s) { comment_ = s; }
136 size_t bitsPerWord() const;
147 const std::vector<ConcreteLocation>& nonParameterInputs() const { return nonParameterInputs_; }
148 std::vector<ConcreteLocation>& nonParameterInputs() { return nonParameterInputs_; }
155 nonParameterInputs_.clear();
158 thisParameter_ = ConcreteLocation();
159 }
160
165 const std::vector<ConcreteLocation>& inputParameters() const { return inputParameters_; }
166
172
177 void clearInputParameters() { inputParameters_.clear(); }
178
189 void appendInputParameter(RegisterDescriptor reg, int64_t offset) {
191 }
192 void appendInputParameter(rose_addr_t va) {
194 }
201 const std::vector<ConcreteLocation>& outputParameters() const { return outputParameters_; }
202
205
210 void clearOutputParameters() { outputParameters_.clear(); }
211
224 void appendOutputParameter(RegisterDescriptor reg, int64_t offset) {
226 }
227 void appendOutputParameter(rose_addr_t va) {
229 }
242 StackParameterOrder stackParameterOrder() const { return stackParameterOrder_; }
243 void stackParameterOrder(StackParameterOrder x) { stackParameterOrder_ = x; }
266 size_t nonParameterStackSize() const {
267 return nonParameterStackSize_;
268 }
269 void nonParameterStackSize(size_t nBytes) {
270 nonParameterStackSize_ = nBytes;
271 }
281 StackDirection stackDirection() const { return stackDirection_; }
282 void stackDirection(StackDirection x) { stackDirection_ = x; }
289
297 StackCleanup stackCleanup() const { return stackCleanup_; }
298 void stackCleanup(StackCleanup x) { stackCleanup_ = x; }
307 const Alignment& stackAlignment() const;
325 const ConcreteLocation& thisParameter() const { return thisParameter_; }
326 void thisParameter(const ConcreteLocation &x) { thisParameter_ = x; }
330 void thisParameter(RegisterDescriptor reg, int64_t offset) {
331 thisParameter(ConcreteLocation(reg, offset));
332 }
333 void thisParameter(rose_addr_t va) {
335 }
344 const ConcreteLocation& returnAddressLocation() const { return returnAddressLocation_; }
345 void returnAddressLocation(const ConcreteLocation &x) { returnAddressLocation_ = x; }
351 RegisterDescriptor instructionPointerRegister() const { return instructionPointerRegister_; }
352 void instructionPointerRegister(RegisterDescriptor x) { instructionPointerRegister_ = x; }
366 const std::set<RegisterDescriptor>& calleeSavedRegisters() const { return calleeSavedRegisters_; }
367 std::set<RegisterDescriptor>& calleeSavedRegisters() { return calleeSavedRegisters_; }
372
380 const std::set<RegisterDescriptor>& scratchRegisters() const { return scratchRegisters_; }
381 std::set<RegisterDescriptor>& scratchRegisters() { return scratchRegisters_; }
386
397
422 void print(std::ostream&) const;
423 void print(std::ostream&, const RegisterDictionaryPtr &regDict) const;
425};
426
427} // namespace
428} // namespace
429} // namespace
430
431#endif
432#endif
Information about alignments.
Definition Alignment.h:16
Information about calling conventions.
Definition Definition.h:30
void stackCleanup(StackCleanup x)
Property: Who pops stack parameters.
Definition Definition.h:298
RegisterParts calleeSavedRegisterParts() const
Compute the set of callee-saved registers.
RegisterParts scratchRegisterParts() const
Computes the set of scratch registers.
size_t bitsPerWord() const
Property: Word size in bits.
void thisParameter(RegisterDescriptor reg)
Property: Object pointer parameter.
Definition Definition.h:327
void stackAlignment(const Alignment &)
Property: Stack alignment.
void thisParameter(RegisterDescriptor reg, int64_t offset)
Property: Object pointer parameter.
Definition Definition.h:330
StackParameterOrder stackParameterOrder() const
Property: Stack parameter order.
Definition Definition.h:242
const std::vector< ConcreteLocation > & outputParameters() const
Property: List of output parameters.
Definition Definition.h:201
RegisterParts outputRegisterParts() const
Computes the set of output registers.
std::vector< ConcreteLocation > & nonParameterInputs()
Non-parameter inputs.
Definition Definition.h:148
~Definition()
Property: Architecture with which this definition is associated.
void stackParameterOrder(StackParameterOrder x)
Property: Stack parameter order.
Definition Definition.h:243
const std::set< RegisterDescriptor > & scratchRegisters() const
Property: Scratch registers.
Definition Definition.h:380
const std::set< RegisterDescriptor > & calleeSavedRegisters() const
Property: Callee-saved registers.
Definition Definition.h:366
void clearInputParameters()
Erase enumerated input parameters.
Definition Definition.h:177
ByteOrder::Endianness byteOrder() const
Property: Order of bytes for multi-byte values in memory.
void instructionPointerRegister(RegisterDescriptor x)
Property: Register that points to next instruction to execute.
Definition Definition.h:352
Definition(const std::string &name, const std::string &comment, const Architecture::BaseConstPtr &)
Property: Architecture with which this definition is associated.
const std::string & name() const
Property: Short name of calling convention.
Definition Definition.h:114
void name(const std::string &s)
Property: Architecture with which this definition is associated.
Definition Definition.h:115
void appendOutputParameter(RegisterDescriptor reg, int64_t offset)
Append output parameter.
Definition Definition.h:224
std::set< RegisterDescriptor > & scratchRegisters()
Property: Scratch registers.
Definition Definition.h:381
RegisterDescriptor instructionPointerRegister() const
Property: Register that points to next instruction to execute.
Definition Definition.h:351
RegisterDictionaryPtr registerDictionary() const
Property: Register dictionary for the architecture.
void appendInputParameter(RegisterDescriptor reg, int64_t offset)
Append input parameter.
Definition Definition.h:189
const Alignment & stackAlignment() const
Property: Stack alignment.
void print(std::ostream &, const RegisterDictionaryPtr &regDict) const
Print detailed information about this calling convention.
void clearOutputParameters()
Erase output parameters.
Definition Definition.h:210
const std::string & comment() const
Property: Full name of calling convention.
Definition Definition.h:125
const std::vector< ConcreteLocation > & inputParameters() const
Property: Enumerated input parameters.
Definition Definition.h:165
const ConcreteLocation & thisParameter() const
Property: Object pointer parameter.
Definition Definition.h:325
size_t nonParameterStackSize() const
Property: Size of non-parameter stack area.
Definition Definition.h:266
void stackDirection(StackDirection x)
Property: Direction that stack grows for a push operation.
Definition Definition.h:282
void print(std::ostream &) const
Print detailed information about this calling convention.
void stackPointerRegister(RegisterDescriptor)
Property: Register for implied stack parameters.
void argumentValueAllocator(const AllocatorPtr &)
Property: Allocator for argument values.
Architecture::BaseConstPtr architecture() const
Property: Architecture with which this definition is associated.
const ConcreteLocation & returnAddressLocation() const
Property: Location of return address.
Definition Definition.h:344
AllocatorPtr argumentValueAllocator() const
Property: Allocator for argument values.
std::set< RegisterDescriptor > & calleeSavedRegisters()
Property: Callee-saved registers.
Definition Definition.h:367
RegisterDescriptor stackPointerRegister() const
Property: Register for implied stack parameters.
AllocatorPtr returnValueAllocator() const
Property: Allocator for return values.
void returnAddressLocation(const ConcreteLocation &x)
Property: Location of return address.
Definition Definition.h:345
void comment(const std::string &s)
Property: Full name of calling convention.
Definition Definition.h:126
RegisterParts getUsedRegisterParts() const
Returns all registers mentioned in this definition.
static Ptr instance(const std::string &name, const std::string &comment, const Architecture::BaseConstPtr &)
Allocating constructor.
void appendInputParameter(RegisterDescriptor reg)
Append input parameter.
Definition Definition.h:186
StackDirection stackDirection() const
Property: Direction that stack grows for a push operation.
Definition Definition.h:281
StackCleanup stackCleanup() const
Property: Who pops stack parameters.
Definition Definition.h:297
void nonParameterStackSize(size_t nBytes)
Property: Size of non-parameter stack area.
Definition Definition.h:269
void appendOutputParameter(rose_addr_t va)
Append output parameter.
Definition Definition.h:227
void appendInputParameter(rose_addr_t va)
Append input parameter.
Definition Definition.h:192
void appendInputParameter(const ConcreteLocation &)
Append input parameter.
void appendOutputParameter(const ConcreteLocation &)
Append output parameter.
void appendOutputParameter(RegisterDescriptor reg)
Append output parameter.
Definition Definition.h:221
const std::vector< ConcreteLocation > & nonParameterInputs() const
Non-parameter inputs.
Definition Definition.h:147
void thisParameter(rose_addr_t va)
Property: Object pointer parameter.
Definition Definition.h:333
RegisterParts inputRegisterParts() const
Compute the set of input registers.
void returnValueAllocator(const AllocatorPtr &)
Property: Allocator for return values.
void thisParameter(const ConcreteLocation &x)
Property: Object pointer parameter.
Definition Definition.h:326
void bitsPerWord(const Sawyer::Optional< size_t > &)
Property: Word size in bits.
Describes (part of) a physical CPU register.
Holds a set of registers without regard for register boundaries.
Holds a value or nothing.
Definition Optional.h:56
Base class for reference counted objects.
std::shared_ptr< const Base > BaseConstPtr
Reference counted pointer for Architecture::Base.
Sawyer::SharedPointer< Definition > DefinitionPtr
Shared-ownership pointer for Definition.
std::shared_ptr< Allocator > AllocatorPtr
Shared-ownership pointer to Allocator.
StackParameterOrder
The order that arguments are pushed onto the stack.
@ UNSPECIFIED
Stack parameter order is unknown or unspecified.
StackCleanup
Who is responsible for popping stack parameters.
@ UNSPECIFIED
Stack parameter cleanup is unknown or unspecified.
@ GROWS_DOWN
A push decrements the stack pointer.
The ROSE library.