Skip to content

Commit

Permalink
Merge Address definition and variable decls
Browse files Browse the repository at this point in the history
  • Loading branch information
hainest committed Nov 3, 2023
1 parent 3ae1f08 commit 3c2ac44
Show file tree
Hide file tree
Showing 63 changed files with 472 additions and 447 deletions.
17 changes: 13 additions & 4 deletions common/h/dyntypes.h
Expand Up @@ -48,6 +48,8 @@
#endif
#endif

#ifdef __cplusplus

#include <functional>
#include <memory>
#include <utility>
Expand All @@ -74,13 +76,15 @@ using dyn_hash_set = std::unordered_set<Key, Hash, Comp, Alloc>;
namespace Dyninst
{
#if defined(_WIN64)
typedef uintptr_t Address;
typedef uintptr_t Offset;
typedef uintptr_t Address;
typedef uintptr_t Offset;
#else
typedef unsigned long Address;
typedef unsigned long Offset;
typedef unsigned long Address;
typedef unsigned long Offset;
#endif

static constexpr Address ADDR_NULL{0};

#if defined(_MSC_VER)
typedef int PID;
typedef HANDLE PROC_HANDLE;
Expand Down Expand Up @@ -119,4 +123,9 @@ namespace Dyninst
} OSType;
}

#else
# define ADDR_NULL (0)
typedef unsigned long Address;
#endif

#endif
2 changes: 1 addition & 1 deletion common/src/Graph.C
Expand Up @@ -40,7 +40,7 @@

using namespace Dyninst;

const Dyninst::Address Graph::INITIAL_ADDR = (Address) -1;
const Dyninst::Address Graph::INITIAL_ADDR = (Dyninst::Address) -1;



Expand Down
14 changes: 5 additions & 9 deletions common/src/Types.h
Expand Up @@ -36,22 +36,15 @@
#if !defined(_Types_h_)
#define _Types_h_

#include "dyntypes.h"

#if defined __cplusplus
# include <cstdint>
#else
# include <stdint.h>
#endif


#if defined(__cplusplus)
#include "common/h/dyntypes.h"
using namespace Dyninst;
static const Address ADDR_NULL = (Address)(0);
#else
#define ADDR_NULL (0)
typedef unsigned long Address;
#endif

typedef long long int RegValue; /* register content 64-bit */
/* This needs to be an int since it is sometimes used to pass offsets
to the code generator (i.e. if-statement) - jkh 5/24/99 */
Expand All @@ -70,6 +63,9 @@ static const Register REG_NULL = (Register)(-1);
#define MAPENTRIES_PATH_SIZE 512
#define MAPENTRIES_PATH_SIZE_STR "512"
typedef struct maps_entries {
#if defined __cplusplus
using Address = Dyninst::Address;
#endif
Address start;
Address end;
unsigned prems;
Expand Down
24 changes: 12 additions & 12 deletions common/src/addrRange.h
Expand Up @@ -54,7 +54,7 @@ typedef enum { TREE_RED, TREE_BLACK } color_t;

class addrRange {
public:
virtual Address get_address() const = 0;
virtual Dyninst::Address get_address() const = 0;
virtual unsigned long get_size() const = 0;
virtual std::string get_name() const {
return std::string("UNNAMED");
Expand All @@ -71,7 +71,7 @@ class addrRangeTree {

/** tree implementation structure. Used to implement the RB tree */
typedef struct entry {
Address key;
Dyninst::Address key;
T *value;
color_t color; /* color of the node */
struct entry* left; /* left child */
Expand All @@ -98,7 +98,7 @@ class addrRangeTree {
* @param d data element
* @param e nill entry
*/
entry(Address key_, T *value_, entry* e)
entry(Dyninst::Address key_, T *value_, entry* e)
: key(key_), value(value_), color(TREE_RED), left(e),
right(e), parent(NULL)
{
Expand Down Expand Up @@ -241,7 +241,7 @@ class addrRangeTree {

// insertion to a binary search tree. It returns the new element pointer
// that is inserted. If element is already there it returns NULL
entry* treeInsert(Address key, T *value)
entry* treeInsert(Dyninst::Address key, T *value)
{
entry* y = NULL;
entry* x = setData;
Expand Down Expand Up @@ -292,7 +292,7 @@ class addrRangeTree {

// method that returns the entry pointer for the element that is searched
//for. If the entry is not found then it retuns NULL
entry* find_internal(Address element) const
entry* find_internal(Dyninst::Address element) const
{
entry* x = setData;
while(x != nil){
Expand Down Expand Up @@ -355,7 +355,7 @@ class addrRangeTree {
}

// Similar to precessor, but returns an entry
bool precessor_internal(Address key, entry * &value) const
bool precessor_internal(Dyninst::Address key, entry * &value) const
{
entry *x = setData;
entry *last = nil;
Expand Down Expand Up @@ -389,7 +389,7 @@ class addrRangeTree {


// Similar to successor, but returns an entry
bool successor_internal(Address key, entry * &value) const
bool successor_internal(Dyninst::Address key, entry * &value) const
{
entry *x = setData;
entry *last = nil;
Expand Down Expand Up @@ -504,7 +504,7 @@ class addrRangeTree {
/** removes the element in the tree
* @param 1 element that will be removed
*/
void remove(Address key)
void remove(Dyninst::Address key)
{
entry* z = find_internal(key);
if(!z)
Expand Down Expand Up @@ -536,7 +536,7 @@ class addrRangeTree {
/** returns true if the argument is member of the addrRangeTree
* @param e the element that will be searched for
*/
virtual bool find(Address key, T *& value) const
virtual bool find(Dyninst::Address key, T *& value) const
{
value = NULL;
if (!precessor(key, value))
Expand All @@ -559,7 +559,7 @@ class addrRangeTree {
/** Fills in the vector with all address ranges that overlap
* with the address range defined by (start, end]
*/
virtual bool find(Address start, Address end,
virtual bool find(Dyninst::Address start, Dyninst::Address end,
std::vector<T *> &ranges) const
{
entry *cur = nil;
Expand All @@ -585,7 +585,7 @@ class addrRangeTree {
/** Returns the largest value less than or equal to the
* key given
*/
virtual bool precessor(Address key, T *& value) const
virtual bool precessor(Dyninst::Address key, T *& value) const
{
entry *val;
bool result = precessor_internal(key, val);
Expand All @@ -599,7 +599,7 @@ class addrRangeTree {
/** Returns the smallest value greater than or equal to the
* key given
*/
virtual bool successor(Address key, T *& value) const
virtual bool successor(Dyninst::Address key, T *& value) const
{
entry *val;
bool result = successor_internal(key, val);
Expand Down
14 changes: 7 additions & 7 deletions common/src/arch-aarch64.C
Expand Up @@ -77,7 +77,7 @@ unsigned instruction::getTargetReg() const {
return -1;
}

Address instruction::getTarget(Address addr) const {
Dyninst::Address instruction::getTarget(Dyninst::Address addr) const {
if (isUncondBranch() || isCondBranch()) {
return getBranchOffset() + addr;
}
Expand All @@ -86,7 +86,7 @@ Address instruction::getTarget(Address addr) const {
}

// TODO: argument _needs_ to be an int, or ABS() doesn't work.
void instruction::setBranchOffset(Address /*newOffset*/) {
void instruction::setBranchOffset(Dyninst::Address /*newOffset*/) {
assert(0);
}

Expand All @@ -98,11 +98,11 @@ bool instruction::isCall() const
return false;
}

void instruction::setInstruction(codeBuf_t * /*ptr*/, Address) {
void instruction::setInstruction(codeBuf_t * /*ptr*/, Dyninst::Address) {
assert(0);
}

void instruction::setInstruction(unsigned char *ptr, Address) {
void instruction::setInstruction(unsigned char *ptr, Dyninst::Address) {
// We don't need the addr on this platform
insn_ = Dyninst::read_memory_as<instructUnion>(ptr);
}
Expand All @@ -129,13 +129,13 @@ bool instruction::isCondBranch() const {
return false;
}

unsigned instruction::jumpSize(Address /*from*/, Address /*to*/, unsigned /*addr_width*/) {
unsigned instruction::jumpSize(Dyninst::Address /*from*/, Dyninst::Address /*to*/, unsigned /*addr_width*/) {
assert(0);
return -1;
}

// -1 is infinite, don't ya know.
unsigned instruction::jumpSize(Address /*disp*/, unsigned /*addr_width*/) {
unsigned instruction::jumpSize(Dyninst::Address /*disp*/, unsigned /*addr_width*/) {
assert(0);
return instruction::size();
}
Expand Down Expand Up @@ -197,7 +197,7 @@ unsigned instruction::getBranchTargetReg() const{
return -1;
}

Address instruction::getBranchOffset() const {
Dyninst::Address instruction::getBranchOffset() const {
if (isUncondBranch()) {
if( CHECK_INST(UNCOND_BR.IMM) ){
return signExtend(GET_OFFSET32(UNCOND_BR.IMM), 26+2 );
Expand Down
20 changes: 10 additions & 10 deletions common/src/arch-aarch64.h
Expand Up @@ -35,7 +35,7 @@

// Code generation

#include "common/src/Types.h"
#include "dyntypes.h"
#include "registers/aarch64_regs.h"
#include <assert.h>
#include <vector>
Expand Down Expand Up @@ -205,7 +205,7 @@ class COMMON_EXPORT instruction {
instruction *copy() const;

void clear() { insn_.raw = 0; }
void setInstruction(codeBuf_t *ptr, Address = 0);
void setInstruction(codeBuf_t *ptr, Dyninst::Address = 0);
void setBits(unsigned int pos, unsigned int len, unsigned int value) {
unsigned int mask;

Expand All @@ -219,7 +219,7 @@ class COMMON_EXPORT instruction {
insn_.raw = insn_.raw | value;
}
unsigned int asInt() const { return insn_.raw; }
void setInstruction(unsigned char *ptr, Address = 0);
void setInstruction(unsigned char *ptr, Dyninst::Address = 0);


// To solve host/target endian mismatches
Expand All @@ -229,14 +229,14 @@ class COMMON_EXPORT instruction {
// We need instruction::size() all _over_ the place.
static unsigned size() { return sizeof(instructUnion); }

Address getBranchOffset() const;
Address getBranchTargetAddress() const;
void setBranchOffset(Address newOffset);
Dyninst::Address getBranchOffset() const;
Dyninst::Address getBranchTargetAddress() const;
void setBranchOffset(Dyninst::Address newOffset);

// And tell us how much space we'll need...
// Returns -1 if we can't do a branch due to architecture limitations
static unsigned jumpSize(Address from, Address to, unsigned addr_width);
static unsigned jumpSize(Address disp, unsigned addr_width);
static unsigned jumpSize(Dyninst::Address from, Dyninst::Address to, unsigned addr_width);
static unsigned jumpSize(Dyninst::Address disp, unsigned addr_width);
static unsigned maxJumpSize(unsigned addr_width);

static unsigned maxInterFunctionJumpSize(unsigned addr_width);
Expand All @@ -261,7 +261,7 @@ class COMMON_EXPORT instruction {
return ((insn_.raw & mask) == match);
}

Address getTarget(Address insnAddr) const;
Dyninst::Address getTarget(Dyninst::Address insnAddr) const;

unsigned spaceToRelocate() const;
bool getUsedRegs(std::vector<int> &regs);
Expand All @@ -273,7 +273,7 @@ class COMMON_EXPORT instruction {

bool isCall() const;

static bool isAligned(Address addr) {
static bool isAligned(Dyninst::Address addr) {
return !(addr & 0x3);
}

Expand Down
16 changes: 8 additions & 8 deletions common/src/arch-power.C
Expand Up @@ -73,7 +73,7 @@ instruction *instruction::copy() const {
return new instruction(*this);
}

Address instruction::getTarget(Address addr) const {
Dyninst::Address instruction::getTarget(Dyninst::Address addr) const {
if (isUncondBranch() || isCondBranch()) {
return getBranchOffset() + addr;
}
Expand All @@ -86,7 +86,7 @@ Address instruction::getTarget(Address addr) const {
}

// TODO: argument _needs_ to be an int, or ABS() doesn't work.
void instruction::setBranchOffset(Address newOffset) {
void instruction::setBranchOffset(Dyninst::Address newOffset) {
if (isUncondBranch()) {
assert(ABS((int) newOffset) < MAX_BRANCH);
IFORM_LI_SET(*this, newOffset >> 2);
Expand All @@ -111,13 +111,13 @@ bool instruction::isCall() const
return(isInsnType(OPmask | AALKmask, CALLmatch));
}

void instruction::setInstruction(codeBuf_t *ptr, Address) {
void instruction::setInstruction(codeBuf_t *ptr, Dyninst::Address) {
// We don't need the addr on this platform

instructUnion *insnPtr = (instructUnion *)ptr;
insn_.raw = (*insnPtr).raw;
}
void instruction::setInstruction(unsigned char *ptr, Address) {
void instruction::setInstruction(unsigned char *ptr, Dyninst::Address) {
// We don't need the addr on this platform
insn_ = Dyninst::read_memory_as<instructUnion>(ptr);
}
Expand All @@ -130,13 +130,13 @@ bool instruction::isCondBranch() const {
return isInsnType(Bmask, BCmatch);
}

unsigned instruction::jumpSize(Address from, Address to, unsigned addr_width) {
Address disp = ABS((long)(to - from));
unsigned instruction::jumpSize(Dyninst::Address from, Dyninst::Address to, unsigned addr_width) {
Dyninst::Address disp = ABS((long)(to - from));
return jumpSize(disp, addr_width);
}

// -1 is infinite, don't ya know.
unsigned instruction::jumpSize(Address disp, unsigned addr_width) {
unsigned instruction::jumpSize(Dyninst::Address disp, unsigned addr_width) {
if (ABS(disp) >= MAX_BRANCH) {
return maxInterFunctionJumpSize(addr_width);
}
Expand Down Expand Up @@ -244,7 +244,7 @@ bool instruction::isThunk() const {
return true;
}

Address instruction::getBranchOffset() const {
Dyninst::Address instruction::getBranchOffset() const {
if (isUncondBranch()) {
return (IFORM_LI(*this) << 2);
}
Expand Down

0 comments on commit 3c2ac44

Please sign in to comment.