Skip to content

Commit

Permalink
Add dyninstAPI/infHeap.h
Browse files Browse the repository at this point in the history
  • Loading branch information
hainest committed Apr 3, 2024
1 parent 9e980eb commit cdc4ff4
Show file tree
Hide file tree
Showing 2 changed files with 133 additions and 26 deletions.
119 changes: 119 additions & 0 deletions docs/dyninstAPI/developer/infHeap.h.rst
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,122 @@
infHeap.h
#########

.. cpp:class:: inferiorHeap

.. cpp:function:: void clear()
.. cpp:function:: inferiorHeap()
.. cpp:function:: inferiorHeap(const inferiorHeap &src)
.. cpp:function:: inferiorHeap &operator=(const inferiorHeap &src)
.. cpp:member:: std::unordered_map<Dyninst::Address, heapItem *> heapActive

active part of heap

.. cpp:member:: std::vector<heapItem *> heapFree

free block of data inferior heap

.. cpp:member:: std::vector<disabledItem> disabledList

items waiting to be freed.

.. cpp:member:: int disabledListTotalMem

total size of item waiting to free

.. cpp:member:: int totalFreeMemAvailable

total free memory in the heap

.. cpp:member:: int freed

total reclaimed(over time)

.. cpp:member:: std::vector<heapItem *> bufferPool

distributed heap segments -- csserra


.. cpp:class:: heapItem

.. cpp:function:: heapItem()
.. cpp:function:: heapItem(Dyninst::Address a, int n, inferiorHeapType t, bool d = true, heapStatus s = HEAPfree)
.. cpp:function:: heapItem(const heapItem *h)
.. cpp:function:: heapItem(const heapItem &h)
.. cpp:function:: heapItem &operator=(const heapItem &src)
.. cpp:function:: void setBuffer(void *b)
.. cpp:member:: Dyninst::Address addr
.. cpp:member:: unsigned length
.. cpp:member:: inferiorHeapType type
.. cpp:member:: bool dynamic

part of a dynamically allocated segment?

.. cpp:member:: heapStatus status
.. cpp:member:: void *buffer

For local...


.. cpp:class:: disabledItem

disabledItem: an item on the heap that we are trying to free.
"pointsToCheck" corresponds to predecessor code blocks (i.e. prior minitrampbasetramp code)

.. cpp:function:: disabledItem() noexcept
.. cpp:function:: disabledItem(heapItem *h, const std::vector<addrVecType> &preds)
.. cpp:function:: disabledItem(const disabledItem &src)
.. cpp:function:: disabledItem &operator=(const disabledItem &src)
.. cpp:function:: ~disabledItem()
.. cpp:member:: heapItem block

inferior heap block

.. cpp:member:: std::vector<addrVecType> pointsToCheck

list of addresses to check against PCs

.. cpp:function:: Dyninst::Address getPointer() const
.. cpp:function:: inferiorHeapType getHeapType() const
.. cpp:function:: const std::vector<addrVecType> &getPointsToCheck() const
.. cpp:function:: std::vector<addrVecType> &getPointsToCheck()

.. cpp:class:: heapDescriptor

Dyninst heap class This needs a better name. Contains a name, and address, and a size. Any ideas?

.. cpp:function:: heapDescriptor(const std::string name, Dyninst::Address addr, unsigned int size, const inferiorHeapType type)
.. cpp:function:: heapDescriptor()
.. cpp:function:: const std::string &name() const
.. cpp:function:: const Dyninst::Address &addr() const
.. cpp:function:: const unsigned &size() const
.. cpp:function:: const inferiorHeapType &type() const
.. cpp:member:: private std::string name_
.. cpp:member:: private Dyninst::Address addr_
.. cpp:member:: private unsigned size_
.. cpp:member:: private inferiorHeapType type_


.. cpp:enum:: heapStatus

.. cpp:enumerator:: HEAPfree
.. cpp:enumerator:: HEAPallocated

.. cpp:enum:: inferiorHeapType

Bit pattern

.. cpp:enumerator:: textHeap=0x01
.. cpp:enumerator:: dataHeap=0x02
.. cpp:enumerator:: uncopiedHeap=0x04

not copied on fork

.. cpp:enumerator:: anyHeap=0x7

OR of the previous three

.. cpp:enumerator:: lowmemHeap=0x1000


.. cpp:type:: std::vector<Dyninst::Address> addrVecType

40 changes: 14 additions & 26 deletions dyninstAPI/src/infHeap.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,11 +43,11 @@
#include "util.h"

typedef enum { HEAPfree, HEAPallocated } heapStatus;
// Bit pattern...

typedef enum { textHeap=0x01,
dataHeap=0x02,
uncopiedHeap=0x04, // not copied on fork
anyHeap=0x7, // OR of the previous three
uncopiedHeap=0x04,
anyHeap=0x7,
lowmemHeap=0x1000 }
inferiorHeapType;
typedef std::vector<Dyninst::Address> addrVecType;
Expand Down Expand Up @@ -91,18 +91,13 @@ class heapItem {
Dyninst::Address addr;
unsigned length;
inferiorHeapType type;
bool dynamic; // part of a dynamically allocated segment?
bool dynamic;
heapStatus status;


// For local...
void *buffer;
};


// disabledItem: an item on the heap that we are trying to free.
// "pointsToCheck" corresponds to predecessor code blocks
// (i.e. prior minitramp/basetramp code)
class disabledItem {
public:
disabledItem() noexcept : block() {}
Expand All @@ -122,20 +117,15 @@ class disabledItem {

~disabledItem() {}

heapItem block; // inferior heap block
std::vector<addrVecType> pointsToCheck; // list of addresses to check against PCs
heapItem block;
std::vector<addrVecType> pointsToCheck;

Dyninst::Address getPointer() const {return block.addr;}
inferiorHeapType getHeapType() const {return block.type;}
const std::vector<addrVecType> &getPointsToCheck() const {return pointsToCheck;}
std::vector<addrVecType> &getPointsToCheck() {return pointsToCheck;}
};

/* Dyninst heap class */
/*
This needs a better name. Contains a name, and address, and a size.
Any ideas?
*/
class heapDescriptor {
public:
heapDescriptor(const std::string name,
Expand Down Expand Up @@ -164,17 +154,15 @@ class inferiorHeap {
inferiorHeap() {
freed = 0; disabledListTotalMem = 0; totalFreeMemAvailable = 0;
}
inferiorHeap(const inferiorHeap &src); // create a new heap that is a copy
// of src (used on fork)
inferiorHeap(const inferiorHeap &src);
inferiorHeap& operator=(const inferiorHeap &src);
std::unordered_map<Dyninst::Address, heapItem*> heapActive; // active part of heap
std::vector<heapItem*> heapFree; // free block of data inferior heap
std::vector<disabledItem> disabledList; // items waiting to be freed.
int disabledListTotalMem; // total size of item waiting to free
int totalFreeMemAvailable; // total free memory in the heap
int freed; // total reclaimed (over time)

std::vector<heapItem *> bufferPool; // distributed heap segments -- csserra
std::unordered_map<Dyninst::Address, heapItem*> heapActive;
std::vector<heapItem*> heapFree;
std::vector<disabledItem> disabledList;
int disabledListTotalMem;
int totalFreeMemAvailable;
int freed;
std::vector<heapItem *> bufferPool;
};

#endif

0 comments on commit cdc4ff4

Please sign in to comment.