1 #ifndef VIRTMEM_BASE_VPTR_H 
    2 #define VIRTMEM_BASE_VPTR_H 
   23 namespace private_utils {
 
   25 template <
bool, 
typename T1, 
typename T2> 
struct Conditional
 
   30 template <
typename T1, 
typename T2> 
struct Conditional<false, T1, T2>
 
   37 template <
typename, 
typename> 
class VPtr;
 
   56     struct Dummy { 
void nonNull(
void) { } };
 
   57     typedef void (Dummy::*TSafeBool)(void);
 
   59     template <
typename, 
typename> 
friend class VPtr;
 
   60     template <
typename> 
friend class VPtrLock;
 
   66 #ifdef VIRTMEM_WRAP_CPOINTERS 
   67 #if defined(__x86_64__) || defined(_M_X64) 
   68     typedef __uint128_t 
PtrNum;
 
   69 #elif defined(__i386) || defined(_M_IX86) 
   79 #ifdef VIRTMEM_WRAP_CPOINTERS 
   80     enum { WRAP_BIT = 
sizeof(
PtrNum) * 8 - 1 }; 
 
   86 #if defined(VIRTMEM_WRAP_CPOINTERS) && (defined(__x86_64__) || defined(_M_X64)) 
  100 #ifdef VIRTMEM_WRAP_CPOINTERS 
  103     static intptr_t getPtrNum(PtrNum p) { 
return p & ~((
PtrNum)1 << WRAP_BIT); }
 
  104     static void *
unwrap(PtrNum p) { ASSERT(
isWrapped(p)); 
return reinterpret_cast<void *
>(getPtrNum(p)); }
 
  106     static intptr_t getPtrNum(PtrNum p) { 
return p; }
 
  108     intptr_t getPtrNum(
void)
 const { 
return getPtrNum(ptr); } 
 
  114     BaseVPtr(
void) = 
default; 
 
  118 #ifdef VIRTMEM_WRAP_CPOINTERS 
  161 #ifdef VIRTMEM_WRAP_CPOINTERS 
  193 #ifndef VIRTMEM_CPP11 
  194     inline bool operator==(
const Null *)
 const { 
return getPtrNum() == 0; }
 
  195     friend inline bool operator==(
const Null *, 
const BaseVPtr &pw) { 
return pw.getPtrNum() == 0; }
 
  196     inline bool operator!=(
const Null *)
 const { 
return getPtrNum() != 0; }
 
  197     friend inline bool operator!=(
const Null *, 
const BaseVPtr &pw) { 
return pw.getPtrNum() != 0; }
 
  199     inline bool operator==(
const NILL_t &)
 const { 
return getPtrNum() == 0; }
 
  200     friend inline bool operator==(
const NILL_t &, 
const BaseVPtr &pw) { 
return pw.getPtrNum() == 0; }
 
  201     inline bool operator!=(
const NILL_t &)
 const { 
return getPtrNum() != 0; }
 
  202     friend inline bool operator!=(
const NILL_t &, 
const BaseVPtr &pw) { 
return pw.getPtrNum() != 0; }
 
  204     inline operator TSafeBool (
void)
 const { 
return getPtrNum() == 0 ? 0 : &Dummy::nonNull; }
 
  214 #if (defined(__x86_64__) || defined(_M_X64) || defined(__i386) || defined(_M_IX86)) && defined(VIRTMEM_WRAP_CPOINTERS) 
  216     inline bool operator!=(
const BaseVPtr &pb)
 const { 
return getPtrNum() != pb.getPtrNum() && 
isWrapped() == pb.isWrapped(); }
 
  217     inline bool operator<(
const BaseVPtr &pb)
 const { 
return getPtrNum() < pb.getPtrNum() && 
isWrapped() == pb.isWrapped(); }
 
  218     inline bool operator<=(
const BaseVPtr &pb)
 const { 
return getPtrNum() <= pb.getPtrNum() && 
isWrapped() == pb.isWrapped(); }
 
  219     inline bool operator>=(
const BaseVPtr &pb)
 const { 
return getPtrNum() >= pb.getPtrNum() && 
isWrapped() == pb.isWrapped(); }
 
  220     inline bool operator>(
const BaseVPtr &pb)
 const { 
return getPtrNum() > pb.getPtrNum() && 
isWrapped() == pb.isWrapped(); }
 
  223     inline bool operator==(
const BaseVPtr &pb)
 const { 
return ptr == pb.ptr; }
 
  224     inline bool operator!=(
const BaseVPtr &pb)
 const { 
return ptr != pb.ptr; }
 
  225     inline bool operator<(
const BaseVPtr &pb)
 const { 
return ptr < pb.ptr; }
 
  226     inline bool operator<=(
const BaseVPtr &pb)
 const { 
return ptr <= pb.ptr; }
 
  227     inline bool operator>=(
const BaseVPtr &pb)
 const { 
return ptr >= pb.ptr; }
 
  228     inline bool operator>(
const BaseVPtr &pb)
 const { 
return ptr > pb.ptr; }
 
  236 #endif // VIRTMEM_BASE_VPTR_H 
contains all code from virtmem 
Definition: base_alloc.cpp:22
PtrNum ptr
Numeric representation of this virtual pointer. 
Definition: base_vptr.h:96
private_utils::Conditional<(sizeof(intptr_t) > sizeof(VPtrNum)), intptr_t, VPtrNum >::type PtrNum
Platform dependent numeric type to store raw (virtual/regular) pointer addresses. ...
Definition: base_vptr.h:72
PtrNum getRawNum(void) const 
Returns a numeric representation of this virtual pointer. 
Definition: base_vptr.h:153
static BaseVPtr wrap(const void *p)
Wraps a regular pointer. 
Definition: base_vptr.h:167
void * unwrap(void)
Provide access to wrapped regular pointer (non static version). 
Definition: base_vptr.h:174
This header file contains several variables that can be used to customize virtmem. 
void setRawNum(PtrNum p)
Sets a virtual pointer from a numeric value. 
Definition: base_vptr.h:159
#define VIRTMEM_EXPLICIT
Used for explicit conversion operators. 
Definition: config.h:72
const void * unwrap(void) const 
Provide access to wrapped regular pointer (non static const version). 
Definition: base_vptr.h:175
uint32_t VPtrNum
Numeric type used to store raw virtual pointer addresses. 
Definition: base_alloc.h:21
virtual memory class header 
Creates a lock to some virtual data. 
Definition: vptr_utils.h:76
bool isWrapped(void) const 
Returns whether a virtual pointer has wrapped a regular pointer (non static version). 
Definition: base_vptr.h:138
static PtrNum getWrapped(PtrNum p)
Returns raw address of regular pointer wrapped by a virtual pointer. 
Definition: base_vptr.h:125
Generalized NULL pointer class. 
Virtual pointer class that provides an interface to access virtual much like 'regular pointers'...
Definition: alloc.h:15
BaseVPtr(NILL_t)
Construct from NILL/nullptr (C++11 only) 
Definition: base_vptr.h:115
void * unwrap(const BaseVPtr &p)
Provide access to wrapped regular pointer. 
Definition: base_vptr.h:173
static bool isWrapped(PtrNum p)
Returns whether a virtual pointer has wrapped a regular pointer. 
Definition: base_vptr.h:132
This is the base class of VPtr and can be used for typeless pointers. 
Definition: base_vptr.h:51