2#ifndef ROSE_SgAsmGenericSection_H
3#define ROSE_SgAsmGenericSection_H
5#include <Cxx_GrammarDeclarations.h>
6#include <SgAsmExecutableFileFormat.h>
27#include <Rose/BinaryAnalysis/AddressIntervalSet.h>
28#include <Rose/BinaryAnalysis/MemoryMap.h>
29#include <Rose/BinaryAnalysis/RelativeVirtualAddress.h>
30#include <sageContainer.h>
32#ifdef ROSE_SgAsmGenericSection_IMPL
33#include <SgAsmBasicString.h>
41#if !defined(DOCUMENTATION)
56#ifdef ROSE_HAVE_BOOST_SERIALIZATION_LIB
58 friend class boost::serialization::access;
64 s & BOOST_SERIALIZATION_NVP(p_file);
65 s & BOOST_SERIALIZATION_NVP(p_header);
66 s & BOOST_SERIALIZATION_NVP(p_size);
67 s & BOOST_SERIALIZATION_NVP(p_offset);
68 s & BOOST_SERIALIZATION_NVP(p_fileAlignment);
69 s & BOOST_SERIALIZATION_NVP(p_data);
70 s & BOOST_SERIALIZATION_NVP(p_purpose);
71 s & BOOST_SERIALIZATION_NVP(p_synthesized);
72 s & BOOST_SERIALIZATION_NVP(p_id);
73 s & BOOST_SERIALIZATION_NVP(p_name);
74 s & BOOST_SERIALIZATION_NVP(p_shortName);
75 s & BOOST_SERIALIZATION_NVP(p_mappedPreferredRva);
76 s & BOOST_SERIALIZATION_NVP(p_mappedSize);
77 s & BOOST_SERIALIZATION_NVP(p_mappedAlignment);
78 s & BOOST_SERIALIZATION_NVP(p_mappedReadPermission);
79 s & BOOST_SERIALIZATION_NVP(p_mappedWritePermission);
80 s & BOOST_SERIALIZATION_NVP(p_mappedExecutePermission);
81 s & BOOST_SERIALIZATION_NVP(p_containsCode);
82 s & BOOST_SERIALIZATION_NVP(p_mappedActualVa);
133 rose_addr_t get_size()
const;
134 virtual void set_size(rose_addr_t);
146 rose_addr_t get_offset()
const;
147 virtual void set_offset(rose_addr_t);
155 rose_addr_t
const& get_fileAlignment()
const;
156 void set_fileAlignment(rose_addr_t
const&);
183 bool const& get_synthesized()
const;
184 void set_synthesized(
bool const&);
193 int const& get_id()
const;
194 void set_id(
int const&);
216 void set_shortName(std::string
const&);
217 std::string get_shortName()
const;
229 rose_addr_t
const& get_mappedPreferredRva()
const;
230 virtual void set_mappedPreferredRva(rose_addr_t);
238 rose_addr_t
const& get_mappedSize()
const;
239 virtual void set_mappedSize(rose_addr_t);
245 rose_addr_t
const& get_mappedAlignment()
const;
246 void set_mappedAlignment(rose_addr_t
const&);
253 bool const& get_mappedReadPermission()
const;
254 void set_mappedReadPermission(
bool const&);
261 bool const& get_mappedWritePermission()
const;
262 void set_mappedWritePermission(
bool const&);
269 bool const& get_mappedExecutePermission()
const;
270 void set_mappedExecutePermission(
bool const&);
283 bool const& get_containsCode()
const;
284 void set_containsCode(
bool const&);
301 rose_addr_t
const& get_mappedActualVa()
const;
302 void set_mappedActualVa(rose_addr_t
const&);
315 unsigned char *local_data_pool;
331 const SgAsmGenericSectionPtrList&);
345 virtual void dump(FILE*,
const char *prefix, ssize_t idx)
const;
348 virtual bool reallocate() {
return false; }
353 virtual void unparse(std::ostream&)
const;
356 void unparse(std::ostream&,
const ExtentMap&)
const;
359 void unparseHoles(std::ostream&)
const;
368 rose_addr_t get_endOffset()
const;
376 void extend(rose_addr_t nbytes);
391 rose_addr_t write(std::ostream &f, rose_addr_t offset,
size_t bufsize,
const void *buf)
const;
392 rose_addr_t write(std::ostream &f, rose_addr_t offset,
const std::string &str)
const;
393 rose_addr_t write(std::ostream &f, rose_addr_t offset,
char c)
const;
394 rose_addr_t write(std::ostream &f, rose_addr_t offset,
const SgFileContentList &buf)
const;
395 rose_addr_t write(std::ostream &f, rose_addr_t offset,
const SgUnsignedCharList &buf)
const;
401 rose_addr_t writeUleb128(
unsigned char*, rose_addr_t offset, uint64_t)
const;
406 rose_addr_t writeSleb128(
unsigned char*, rose_addr_t offset, int64_t)
const;
415 size_t readContent(rose_addr_t abs_offset,
void *dst_buf, rose_addr_t size,
bool strict=
true);
429 rose_addr_t size,
bool strict=
true);
431 void *dst_buf, rose_addr_t size,
bool strict=
true);
440 size_t readContentLocal(rose_addr_t rel_offset,
void *dst_buf, rose_addr_t size,
bool strict=
true);
457 std::string readContentString(rose_addr_t abs_offset,
bool strict=
true);
467 std::string readContentLocalString(rose_addr_t rel_offset,
bool strict=
true);
473 SgUnsignedCharList readContentLocalUcl(rose_addr_t rel_offset, rose_addr_t size);
480 int64_t readContentLocalSleb128(rose_addr_t *rel_offset,
bool strict=
true);
487 uint64_t readContentLocalUleb128(rose_addr_t *rel_offset,
bool strict=
true);
496 unsigned char *writableContent(
size_t nbytes);
515 bool isMapped()
const;
526 rose_addr_t get_baseVa()
const;
531 rose_addr_t get_mappedPreferredVa()
const;
537 rose_addr_t get_vaOffset(rose_addr_t va)
const;
543 rose_addr_t get_rvaOffset(rose_addr_t rva)
const;
548 Extent get_fileExtent()
const;
554 Extent get_mappedPreferredExtent()
const;
578 rose_addr_t get_file_alignment() const ROSE_DEPRECATED("use get_fileAlignment");
579 void set_file_alignment(rose_addr_t) ROSE_DEPRECATED("use set_fileAlignment");
580 std::
string get_short_name() const ROSE_DEPRECATED("use get_shortName");
581 void set_short_name(const std::
string&) ROSE_DEPRECATED("use set_shortName");
582 rose_addr_t get_mapped_preferred_rva() const ROSE_DEPRECATED("use get_mappedPreferredRva");
583 void set_mapped_preferred_rva(rose_addr_t) ROSE_DEPRECATED("use set_mappedPreferredRva");
584 rose_addr_t get_mapped_size() const ROSE_DEPRECATED("use get_mappedSize");
585 void set_mapped_size(rose_addr_t) ROSE_DEPRECATED("use set_mappedSize");
586 rose_addr_t get_mapped_alignment() const ROSE_DEPRECATED("use get_mappedAlignment");
587 void set_mapped_alignment(rose_addr_t) ROSE_DEPRECATED("use set_mappedAlignment");
588 bool get_mapped_rperm() const ROSE_DEPRECATED("use get_mappedReadPermission");
589 void set_mapped_rperm(
bool) ROSE_DEPRECATED("use set_mappedReadPermission");
590 bool get_mapped_wperm() const ROSE_DEPRECATED("use get_mappedWritePermission");
591 void set_mapped_wperm(
bool) ROSE_DEPRECATED("use set_mappedWritePermission");
592 bool get_mapped_xperm() const ROSE_DEPRECATED("use get_mappedExecutePermission");
593 void set_mapped_xperm(
bool) ROSE_DEPRECATED("use set_mappedExecutePermission");
594 bool get_contains_code() const ROSE_DEPRECATED("use get_containsCode");
595 void set_contains_code(
bool) ROSE_DEPRECATED("use set_containsCode");
596 rose_addr_t get_mapped_actual_va() const ROSE_DEPRECATED("use get_mappedActualVa");
597 void set_mapped_actual_va(rose_addr_t) ROSE_DEPRECATED("use set_mappedActualVa");
598 static
void dump_containing_sections(FILE*, const std::
string&,
Rose::BinaryAnalysis::RelativeVirtualAddress,
599 const SgAsmGenericSectionPtrList&)
600 ROSE_DEPRECATED("use dumpContainingSections");
601 void grab_content() ROSE_DEPRECATED("use grabContent");
602 void unparse_holes(std::ostream&) const ROSE_DEPRECATED("use unparseHoles");
604 rose_addr_t get_end_offset() const ROSE_DEPRECATED("use get_endOffset");
605 rose_addr_t write_uleb128(
unsigned char*, rose_addr_t, uint64_t) const ROSE_DEPRECATED("use writeUleb128");
606 rose_addr_t write_sleb128(
unsigned char*, rose_addr_t, int64_t) const ROSE_DEPRECATED("use writeSleb128");
607 size_t read_content(rose_addr_t,
void*, rose_addr_t,
bool=true) ROSE_DEPRECATED("use readContent");
608 size_t read_content(const
Rose::BinaryAnalysis::MemoryMap::Ptr&, rose_addr_t,
void*, rose_addr_t,
bool=true)
609 ROSE_DEPRECATED("use readContent");
610 size_t read_content(const
Rose::BinaryAnalysis::MemoryMap::Ptr&, const
Rose::BinaryAnalysis::RelativeVirtualAddress&,
void*,
611 rose_addr_t,
bool=true)
612 ROSE_DEPRECATED("use readContent");
613 size_t read_content_local(rose_addr_t,
void*, rose_addr_t,
bool=true) ROSE_DEPRECATED("use readContentLocal");
614 std::
string read_content_str(const
Rose::BinaryAnalysis::MemoryMap::Ptr&, rose_addr_t,
bool=true)
615 ROSE_DEPRECATED("use readContentString");
616 std::
string read_content_str(rose_addr_t,
bool=true) ROSE_DEPRECATED("use readContentString");
617 std::
string read_content_str(const
Rose::BinaryAnalysis::MemoryMap::Ptr&,
Rose::BinaryAnalysis::RelativeVirtualAddress,
619 ROSE_DEPRECATED("use readContentString");
620 std::
string read_content_local_str(rose_addr_t,
bool=true) ROSE_DEPRECATED("use readContentLocalString");
621 SgUnsignedCharList read_content_local_ucl(rose_addr_t, rose_addr_t) ROSE_DEPRECATED("use readContentLocalUcl");
622 int64_t read_content_local_sleb128(rose_addr_t*,
bool=true) ROSE_DEPRECATED("use readContentLocalSleb128");
623 uint64_t read_content_local_uleb128(rose_addr_t*,
bool=true) ROSE_DEPRECATED("use readContentLocalUleb128");
624 unsigned char *writable_content(
size_t) ROSE_DEPRECATED("use writableContent");
625 Rose::BinaryAnalysis::AddressIntervalSet get_referenced_extents() const ROSE_DEPRECATED("use get_referencedExtents");
626 Rose::BinaryAnalysis::AddressIntervalSet get_unreferenced_extents() const ROSE_DEPRECATED("use get_unreferencedExtents");
627 bool is_mapped() const ROSE_DEPRECATED("use isMapped");
628 void clear_mapped() ROSE_DEPRECATED("use clearMapped");
629 rose_addr_t get_base_va() const ROSE_DEPRECATED("use get_baseVa");
630 rose_addr_t get_mapped_preferred_va() const ROSE_DEPRECATED("use get_mappedPreferredVa");
631 rose_addr_t get_va_offset(rose_addr_t) const ROSE_DEPRECATED("use get_vaOffset");
632 rose_addr_t get_rva_offset(rose_addr_t) const ROSE_DEPRECATED("use get_rvaOffset");
633 Extent get_file_extent() const ROSE_DEPRECATED("use get_fileExtent");
634 Extent get_mapped_preferred_extent() const ROSE_DEPRECATED("use get_mappedPreferredExtent");
650 void initializeProperties();
669 virtual std::
string class_name() const override;
672 virtual VariantT variantT() const override;
677 enum { static_variant = V_SgAsmGenericSection };
692 static const unsigned pool_size;
694 static std::vector<unsigned char *> pools;
699 static unsigned long initializeStorageClassArray(SgAsmGenericSectionStorageClass *);
702 static void clearMemoryPool();
703 static void deleteMemoryPool();
706 static void extendMemoryPoolForFileIO();
711 static SgAsmGenericSection * getPointerFromGlobalIndex(AstSpecificDataManagingClass *,
unsigned long);
714 static unsigned long getNumberOfValidNodesAndSetGlobalIndexInFreepointer(
unsigned long);
716 static void resetValidFreepointers();
718 static unsigned long getNumberOfLastValidPointer();
721#if defined(INLINE_FUNCTIONS)
723 inline void *
operator new (
size_t size);
726 void *
operator new (
size_t size);
729 void operator delete (
void* pointer,
size_t size);
732 void operator delete (
void* pointer)
778#ifndef ROSE_USE_INTERNAL_FRONTEND_DEVELOPMENT
781 virtual RTIReturnType
roseRTI()
override;
795 virtual const char*
sage_class_name() const override ROSE_DEPRECATED_FUNCTION;
801 virtual int variant() const ROSE_DEPRECATED_FUNCTION;
983 friend class SgAsmGenericSectionStorageClass;
986 friend class AstSpecificDataManagingClass;
989 friend class AstSpecificDataManagingClassStorageClass;
1021#define BUILD_ATERM_SUPPORT 0
1022 #if BUILD_ATERM_SUPPORT
1023 #ifdef ROSE_USE_ROSE_ATERM_SUPPORT
1035 virtual ATerm generate_ATerm()
override;
1038 virtual void generate_ATerm_Annotation(ATerm & term)
override;
1094rose_addr_t p_offset;
1098rose_addr_t p_fileAlignment;
1122std::string p_shortName;
1126rose_addr_t p_mappedPreferredRva;
1130rose_addr_t p_mappedSize;
1134rose_addr_t p_mappedAlignment;
1138bool p_mappedReadPermission;
1142bool p_mappedWritePermission;
1146bool p_mappedExecutePermission;
1154rose_addr_t p_mappedActualVa;
Class holding static data and functions supporting File I/O.
Attribute containing a regex expression as a string.
A contiguous range of values.
Optionally bound relative virtual address.
Base class for binary files.
Contiguous region of a file.
SectionPurpose
Reason for section's existence.
Base class for strings related to binary specimens.
Supporting class from copy mechanism within ROSE.
This class represents the base class for all IR nodes within Sage III.
virtual size_t get_numberOfTraversalSuccessors()
return number of children in the traversal successor list
virtual RTIReturnType roseRTI()
return C++ Runtime-Time-Information
virtual std::vector< std::string > get_traversalSuccessorNamesContainer()
container of names of variables or container indices used used in the traversal to access AST success...
virtual void debugSerializationEnd(const char *className)
Called by generated serializers.
static std::string getNodeIdString(SgNode *sgnode)
compute the NodeId for a particular SgNode*.
virtual bool isInMemoryPool()
FOR INTERNAL USE This is used in internal tests to verify that all IR nodes are allocated from the he...
int variant() const
Older version function returns enum value "NODE".
virtual void processDataMemberReferenceToPointers(ReferenceToPointerHandler *)
FOR INTERNAL USE Processes pairs of references to SgNode* and strings for use in AST tools
virtual long getChildIndex(SgNode *childNode) const
FOR INTERNAL USE Returns a unique index value for the childNode in the list of children at this IR no...
virtual size_t get_childIndex(SgNode *child)
index-based access to traversal successors by child node
virtual void debugSerializationBegin(const char *className)
Called by generated serializers.
virtual std::vector< SgNode * > get_traversalSuccessorContainer()
container of pointers to AST successor nodes used in the traversal overridden in every class by gener...
static void visitRepresentativeNode(ROSE_VisitTraversal &visit)
FOR INTERNAL USE Support for type-based traversal.
virtual void checkDataMemberPointersIfInMemoryPool()
FOR INTERNAL USE This is used in internal tests to verify that all IR nodes are allocated from the he...
static size_t numberOfNodes()
Returns the total number of IR nodes of this type.
virtual void accept(ROSE_VisitorPattern &visitor)
support for the classic visitor pattern done in GoF
virtual SgNode * get_traversalSuccessorByIndex(size_t idx)
index-based access to traversal successors by index number
static void traverseMemoryPoolVisitorPattern(ROSE_VisitorPattern &visitor)
FOR INTERNAL USE Support for visitor pattern.
void executeVisitorMemberFunction(ROSE_VisitorPattern &visitor)
FOR INTERNAL USE Support for visitor pattern.
static SgNode * getNodeByNodeId(VariantT variantT, size_t poolIdx, size_t itemIdx)
Find a node by its variant type, pool index, and item index.
static size_t memoryUsage()
Returns the size in bytes of the total memory allocated for all IR nodes of this type.
static void traverseMemoryPoolNodes(ROSE_VisitTraversal &visit)
FOR INTERNAL USE Support for visitor pattern over all IR nodes by type of IR node.
virtual const char * sage_class_name() const
generates string representing the class name: (e.g. for SgNode returns "SgNode").
virtual std::vector< std::pair< SgNode *, std::string > > returnDataMemberPointers() const
FOR INTERNAL USE Returns STL vector of pairs of SgNode* and strings for use in AST tools
static SgNode * getNodeByNodeIdInternal(size_t poolIdx, size_t itemIdx)
FOR INTERNAL USE Find an SgNode from its memory pool and location therin.
SgNode * addRegExpAttribute(std::string s, AstRegExAttribute *a)
Support for AST matching using regular expression.
virtual void destructorHelper()
This gets called by all Rosebud-generated destructors.
void parse(SgAsmGenericFile *)
Main function to parse DWARF information.
void serialize(std::ostream &output, Graph &graph)
Serialize a graph into a stream of bytes.
ROSE_DLL_API int set_name(SgInitializedName *initializedNameNode, SgName new_name)
set_name of symbol in symbol table.
std::string get_name(const SgNode *node)
Generate a useful name to describe the SgNode.
void copy(const Word *src, const BitRange &srcRange, Word *dst, const BitRange &dstRange)
Copy some bits.
const char * SectionPurpose(int64_t)
Convert SgAsmGenericSection::SectionPurpose enum constant to a string.